Page 1 of 1
importing image on clipboard using imageData
Posted: Sun Aug 01, 2021 4:56 am
by rodneyt
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
Re: importing image on clipboard using imageData
Posted: Sun Aug 01, 2021 10:12 am
by jmburnod
Hi,
You may try "text" instead "image data"
Code: Select all
set the text of image "clipImage" to clipboarddata["image"]
Best regards
Jean-Marc
Re: importing image on clipboard using imageData
Posted: Sun Aug 01, 2021 6:17 pm
by jacque
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.
Re: importing image on clipboard using imageData
Posted: Sun Aug 01, 2021 9:43 pm
by FourthWorld
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.
Re: importing image on clipboard using imageData
Posted: Sun Aug 01, 2021 11:04 pm
by rodneyt
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
Re: importing image on clipboard using imageData
Posted: Sun Aug 01, 2021 11:49 pm
by jmburnod
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
Re: importing image on clipboard using imageData
Posted: Sun Aug 01, 2021 11:54 pm
by rodneyt
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
Re: importing image on clipboard using imageData
Posted: Mon Aug 02, 2021 3:25 am
by andresdt
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
Re: importing image on clipboard using imageData
Posted: Mon Aug 02, 2021 3:51 am
by rodneyt
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"]
Re: importing image on clipboard using imageData
Posted: Mon Aug 02, 2021 4:15 am
by jacque
Or maybe (untested)
Code: Select all
if the clipboard = "image" then paste
Presumably LC will figure out the rectangle.
Re: importing image on clipboard using imageData
Posted: Mon Aug 02, 2021 4:21 am
by rodneyt
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