Page 1 of 1

Export Snapshot into Card

Posted: Wed Oct 21, 2020 12:09 pm
by Xero
OK... I have been running in circles and need the brainstrust again!
I have a substack that has a field with text in it. I want to convert the card into an image (jpeg) so I can use that as part of an image manipulation. The image will then be read as Black or White pixels, and "inserted" into another image by 'adjusting' the values of the channels.
When an image is loaded that will be 'adjusted', a substack with a dummy image and field will open and be adjusted to be the same size as the loaded image. It is important that the image and the field be physically the same size.
I have got the image manipulation part all coded and working wonderfully, but damned if I can work out how to do the simple bit!!!
I need to: Take a snapshot of a card, convert it into a jpeg, place it on the same card. I currently have a dummy image called "Image" on the card.
I have:

Code: Select all

on CodeImage
   go to stack "code" of this stack --may be redundant--
   export snapshot from card "Code" of stack "Code" to tCodeFile AS JPEG
   set the imageData of image "Image" of stack "Code" to tCodeFile
   --do more stuff--
   end CodeImage
The problem I am encountering is this: When I run this code, the image "Image" has a strip down the left side with coloured static, and nothing else.
When I change the script to read:

Code: Select all

export snapshot from card "Code" of stack "Code" to file "Code.jpg" as JPEG
I get exactly what I want... but it's on my harddrive, not my livecode.
I'm clearly missing something fundamental, but it's not so fun, so I am just getting da mental... :D
Help please!
Thanks in advance.
XdM

Re: Export Snapshot into Card

Posted: Wed Oct 21, 2020 1:34 pm
by jmburnod
Hi,
tCodeFile is not a path.
You need ending with extension.
Once you have exported your snapshot you can import data or use filename

Code: Select all

 
 ... 
   put specialfolderpath("documents") & "/ " & "tCodeFile.jpg" into tPath
   export snapshot from this card to file  tPath AS JPEG
   set the filename of image "image" to tPath -- fileName option
   set the text of image "image" to url("binfile:" & tPath) -- data option
...
   
Best regards
Jean-Marc

Re: Export Snapshot into Card

Posted: Wed Oct 21, 2020 1:43 pm
by Klaus
jmburnod wrote:
Wed Oct 21, 2020 1:34 pm
Hi,
tCodeFile is not a path.
...
True, but we can also export a snapshot to a VARIABLE, which is obviously the case here!

Re: Export Snapshot into Card

Posted: Wed Oct 21, 2020 2:28 pm
by jmburnod
What Klaus said and also:

Code: Select all

import snapshot from this card
set the name of last img to "image"
Jean-Marc

Re: Export Snapshot into Card

Posted: Wed Oct 21, 2020 2:48 pm
by Klaus
Ah, I think I know why this did not work:

Code: Select all

on CodeImage
   go to stack "code" of this stack --may be redundant--
   export snapshot from card "Code" of stack "Code" to tCodeFile AS JPEG
   ## set the imageData of image "Image" of stack "Code" to tCodeFile
   --do more stuff--
end CodeImage
Setting the IMAGEDATA of an image requires that both the target image and the source image (or its data)
have the EXACT dimension (width and height). If they don't fit, you see strange (colorful) or even no results. :-)

So just use:

Code: Select all

...
## set the imageData of image "Image" of stack "Code" to tCodeFile
set the TEXT of image "Image" of stack "Code" to tCodeFile
...
That should do the trick.

Re: Export Snapshot into Card

Posted: Wed Oct 21, 2020 3:48 pm
by Xero
Klaus...
You've done it again!
I don't think I could finish any new ideas without you!
"text" instead of "imagedata" has worked. Not sure why, but it's good to go.
I'll post the stack here when it's a little more polished. A nice fun little image manipulator.
X

Re: Export Snapshot into Card

Posted: Wed Oct 21, 2020 4:42 pm
by richmond62
I don't know about the above . . . but take a look at my simple-pimple stuff over here:

http://forums.livecode.com/viewtopic.php?f=8&t=34779

This IMPORTS a snapshot, CUTS it, and then POSTS it to another card.

Re: Export Snapshot into Card

Posted: Thu Oct 22, 2020 9:30 pm
by jiml
Hi,

While you can name an image "Image" it may lead to later confusion.
Same with a card named "Code" in a stack named "Code"

I speak from hard learned experience. :D

JimL