importing image on clipboard using imageData
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller
importing image on clipboard using imageData
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
- 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
-
- 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
Hi,
You may try "text" instead "image data"
Best regards
Jean-Marc
You may try "text" instead "image data"
Code: Select all
set the text of image "clipImage" to clipboarddata["image"]
Jean-Marc
https://alternatic.ch
-
- VIP Livecode Opensource Backer
- Posts: 7237
- Joined: Sat Apr 08, 2006 8:31 pm
- Location: Minneapolis MN
- Contact:
Re: importing image on clipboard using imageData
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
HyperActive Software | http://www.hyperactivesw.com
-
- VIP Livecode Opensource Backer
- Posts: 9842
- Joined: Sat Apr 08, 2006 7:05 am
- Location: Los Angeles
- Contact:
Re: importing image on clipboard using imageData
Am I the only one who cringes at syntax for setting an IMAGE by setting its TEXT?jmburnod wrote: ↑Sun Aug 01, 2021 10:12 amYou may try "text" instead "image data"Code: Select all
set the text of image "clipImage" to clipboarddata["image"]
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
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn
Re: importing image on clipboard using imageData
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
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
-
- 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
Yes, it is strange,Am I the only one who cringes at syntax for setting an IMAGE by setting its TEXT?
I was surprised first time i used it but it works
YesJust seems a sadly unintuitive gotcha semantically.
Jean-Marc
https://alternatic.ch
Re: importing image on clipboard using imageData
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
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
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:
so in your case it would be something like this
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
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
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"]
Thanks for clarifying that!
set the imageData of image "clipImage" to clipboarddata["image"]
-
- VIP Livecode Opensource Backer
- Posts: 7237
- Joined: Sat Apr 08, 2006 8:31 pm
- Location: Minneapolis MN
- Contact:
Re: importing image on clipboard using imageData
Or maybe (untested)
Presumably LC will figure out the rectangle.
Code: Select all
if the clipboard = "image" then paste
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com
HyperActive Software | http://www.hyperactivesw.com
Re: importing image on clipboard using imageData
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
Key takeaway: If you put the data into the image, the problems go away....
~ Rodney