importing image on clipboard using imageData

Anything beyond the basics in using the LiveCode language. Share your handlers, functions and magic here.

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
rodneyt
Posts: 128
Joined: Wed Oct 17, 2018 7:32 am

importing image on clipboard using imageData

Post by rodneyt » Sun Aug 01, 2021 4:56 am

On OSX it is possible to take a screenshot directly to the clipboard. To configure type apple + shift + 5 and choose destination (under options) for screenshots to go to the clipboard.

- take a screenshot
- in livecode the clipboard returns "image"
- try importing clipboard to an image using: set the imageData of image "clipImage" to clipboarddata["image"]

... results in a distorted image.

Any idea what am I doing wrong here?

~ Rodney

jmburnod
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 2718
Joined: Sat Dec 22, 2007 5:35 pm
Location: Genève
Contact:

Re: importing image on clipboard using imageData

Post by jmburnod » Sun Aug 01, 2021 10:12 am

Hi,
You may try "text" instead "image data"

Code: Select all

set the text of image "clipImage" to clipboarddata["image"]
Best regards
Jean-Marc
https://alternatic.ch

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 7210
Joined: Sat Apr 08, 2006 8:31 pm
Location: Minneapolis MN
Contact:

Re: importing image on clipboard using imageData

Post by jacque » Sun Aug 01, 2021 6:17 pm

ImageData must match the rect of the target image exactly, otherwise it will distort as you describe. Even a single pixel difference matters. So you need to determine the rect of the copied image and set the target image control to the same size before setting its imageData.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9801
Joined: Sat Apr 08, 2006 7:05 am
Location: Los Angeles
Contact:

Re: importing image on clipboard using imageData

Post by FourthWorld » Sun Aug 01, 2021 9:43 pm

jmburnod wrote:
Sun Aug 01, 2021 10:12 am
You may try "text" instead "image data"

Code: Select all

set the text of image "clipImage" to clipboarddata["image"]
Am I the only one who cringes at syntax for setting an IMAGE by setting its TEXT?

I know the background of it. Just seems a sadly unintuitive gotcha semantically.
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

rodneyt
Posts: 128
Joined: Wed Oct 17, 2018 7:32 am

Re: importing image on clipboard using imageData

Post by rodneyt » Sun Aug 01, 2021 11:04 pm

OK we're making progress here, I think. How does one determine the rect of an image on the clipboard - as in this case it is a screenshot the user has just grabbed?

I note that typing Cmd + V will paste the clipboard image as a new Livecode image on the card. I guess my next step if no-one knows is to dig through Livecode's IDE scripts to find out how that is being done....

~ R

jmburnod
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 2718
Joined: Sat Dec 22, 2007 5:35 pm
Location: Genève
Contact:

Re: importing image on clipboard using imageData

Post by jmburnod » Sun Aug 01, 2021 11:49 pm

Am I the only one who cringes at syntax for setting an IMAGE by setting its TEXT?
Yes, it is strange,
I was surprised first time i used it but it works
Just seems a sadly unintuitive gotcha semantically.
Yes
Jean-Marc
https://alternatic.ch

rodneyt
Posts: 128
Joined: Wed Oct 17, 2018 7:32 am

Re: importing image on clipboard using imageData

Post by rodneyt » Sun Aug 01, 2021 11:54 pm

Here's my problem with it - nowhere in imageData entry in the Dictionary does it mention this.

Can someone point me to the "history" on why setting image data uses Text. I will make a continuous improvement entry in the bug/enhancement database to fix this.

I think it should be referenced under obvious places where a user might be trying to get up to speed on this such as imageData and clipboarddata["image"].

Jacque's point about needing to know the rect of an image when setting imageData is also not discussed in those entries, once I understand the solution to this problem we can document that too for the dictionary (if it is not already in there - and if it is - can someone point me to the relevant entry?)

~ Rodney

andresdt
Posts: 146
Joined: Fri Aug 16, 2019 7:51 pm

Re: importing image on clipboard using imageData

Post by andresdt » Mon Aug 02, 2021 3:25 am

Taken from Livecode Dictionary

Tip: To copy the information into an image at full resolution, regardless of whether its height and width have been changed, use a declaration like the following:

Code: Select all

put the "Full Resolution" image in the "Copied Image" image
so in your case it would be something like this

Code: Select all

 local tClipboardDataImage
    
 put the clipboardData ["image"] into tClipboardDataImage
    
 if tClipboardDataImage is no empty then
      put tClipboardDataImage into image "img1"
      set the clipboardData ["image"] to empty
 end if

rodneyt
Posts: 128
Joined: Wed Oct 17, 2018 7:32 am

Re: importing image on clipboard using imageData

Post by rodneyt » Mon Aug 02, 2021 3:51 am

OK great - so what I was doing wrong: I just need to put clipboarddata["image"] into the image rather than setting the imageData of image

Thanks for clarifying that!

set the imageData of image "clipImage" to clipboarddata["image"]

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 7210
Joined: Sat Apr 08, 2006 8:31 pm
Location: Minneapolis MN
Contact:

Re: importing image on clipboard using imageData

Post by jacque » Mon Aug 02, 2021 4:15 am

Or maybe (untested)

Code: Select all

if the clipboard = "image" then paste 
Presumably LC will figure out the rectangle.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

rodneyt
Posts: 128
Joined: Wed Oct 17, 2018 7:32 am

Re: importing image on clipboard using imageData

Post by rodneyt » Mon Aug 02, 2021 4:21 am

Yep. The key thing is: if you "put [data] into img" it's different than if you "set the imageData of img ... to [data]". See example above.

Key takeaway: If you put the data into the image, the problems go away....

~ Rodney

Post Reply

Return to “Talking LiveCode”