Export Snapshot into Card

Visuals, audio, animation. Blended, not stirred. If LiveCode is part of your rich media production toolbox, this is the forum for you.

Moderators: Klaus, FourthWorld, heatherlaine, kevinmiller, robinmiller

Post Reply
Xero
Posts: 93
Joined: Sat Jun 23, 2018 2:22 pm

Export Snapshot into Card

Post by Xero » Wed Oct 21, 2020 12:09 pm

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

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

Re: Export Snapshot into Card

Post by jmburnod » Wed Oct 21, 2020 1:34 pm

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

Klaus
Posts: 12286
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: Export Snapshot into Card

Post by Klaus » Wed Oct 21, 2020 1:43 pm

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!

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

Re: Export Snapshot into Card

Post by jmburnod » Wed Oct 21, 2020 2:28 pm

What Klaus said and also:

Code: Select all

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

Klaus
Posts: 12286
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: Export Snapshot into Card

Post by Klaus » Wed Oct 21, 2020 2:48 pm

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.

Xero
Posts: 93
Joined: Sat Jun 23, 2018 2:22 pm

Re: Export Snapshot into Card

Post by Xero » Wed Oct 21, 2020 3:48 pm

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

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 5620
Joined: Fri Feb 19, 2010 10:17 am
Location: Bulgaria

Re: Export Snapshot into Card

Post by richmond62 » Wed Oct 21, 2020 4:42 pm

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.

jiml
Posts: 246
Joined: Sat Dec 09, 2006 1:27 am
Location: Los Angeles

Re: Export Snapshot into Card

Post by jiml » Thu Oct 22, 2020 9:30 pm

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

Post Reply

Return to “Multimedia”