Export snapshot of group to jpg

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller

Post Reply
propeller
Posts: 22
Joined: Sat Oct 13, 2018 12:22 pm
Location: Austria

Export snapshot of group to jpg

Post by propeller » Mon Oct 29, 2018 1:17 pm

hi there,

i do my first tiny steps in livecode at the moment. what i created so far: i have a group "Canvas" where two images "BackgroundImage" and "OVL" are loaded. i can scale them and move them around. i have a button "Export" which should make a snapshot of the "Canvas"-Group and export it as a jpg but it does not seem to do the trick. i can not find the resulting image on my mac "hollawind.jpg". what am i doing wrong?

Code: Select all

on mouseUp
   export snapshot from group "Canvas" to file "hollawind.jpg" as JPEG
   end mouseUp
it would be great if someone would/could help me on this one.

Have a nice day!

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

Re: Export snapshot of group to jpg

Post by Klaus » Mon Oct 29, 2018 1:37 pm

Hi propeller,

if you do not specify an absolute pathname, then "the defaultfolder" is the target folder.
If you do not know where this folder is at that point, well, then you should consider to use a pathname where we are allowed to write and where we know where it is! 8)

If this happens in the IDE, probably "the defaultfolder" might be the "Programme" (Applications) folder or even a folder inside of the Livecode.app application bundle! I'm sure you will find your pic there.

In a standalone this is definitively not a place werhe we have write permission so this will fail in a runtime.

Do something like this:

Code: Select all

...
## Desktop:
put specialfolderpath("desktop") & "/hollawind.jpg into tFile

## Or the current users Documents folder:
## put specialfolderpath("documents") & "/hollawind.jpg into tFile
export snapshot from group "Canvas" to file tFile as JPEG
...
Best

Klaus

propeller
Posts: 22
Joined: Sat Oct 13, 2018 12:22 pm
Location: Austria

Re: Export snapshot of group to jpg

Post by propeller » Mon Oct 29, 2018 2:22 pm

Dear Klaus,

thank you for your answer. this did the trick. you are great!

Have a nice day.

bogs
Posts: 5435
Joined: Sat Feb 25, 2017 10:45 pm

Re: Export snapshot of group to jpg

Post by bogs » Mon Oct 29, 2018 5:09 pm

Klaus wrote:
Mon Oct 29, 2018 1:37 pm
If this happens in the IDE, probably "the defaultfolder" might be the "Programme" (Applications) folder or even a folder inside of the Livecode.app application bundle! I'm sure you will find your pic there.

In a standalone this is definitively not a place werhe we have write permission so this will fail in a runtime.
Not to discount Klaus's excellent advice, since you should know where the file is going to be saved, but as an addendum of sorts about the default folder.

If in the IDE, instead of trying to look at the places the default folder might be, you can open the message box and type -

Code: Select all

put the defaultFolder
This will tell you where the default folder is when you are developing. Remember that this can be changed in code at times, so if it does, simply bring the message box back up and check.
Selection_079.png
Message Box...
Selection_079.png (11.41 KiB) Viewed 4107 times
In a standalone, you can find the default folder in a number of ways as well, either with the answer dialog (if you just want the location), or with the answer folder dialog if you actually want to open the location up.

Code: Select all

on mouseUp
   answer folder"where" with the defaultFolder
end mouseUp
As you can see, this opens the answer dialog to the direct folder directory -
Selection_080.png
Answer Folder dialog...
Image

propeller
Posts: 22
Joined: Sat Oct 13, 2018 12:22 pm
Location: Austria

Re: Export snapshot of group to jpg

Post by propeller » Mon Oct 29, 2018 5:12 pm

dear bogs!

thank you for sharing. this is helpful. :!:

ClipArtGuy
Posts: 253
Joined: Wed Aug 19, 2015 4:29 pm

Re: Export snapshot of group to jpg

Post by ClipArtGuy » Mon Oct 29, 2018 5:51 pm

As an addendum to Bogs' addendum, you can also set the default folder, so something like this works as well.

Code: Select all

on mouseup
   set the defaultfolder to specialfolderpath("Desktop")  
   export snapshot from grp 1 to file "sample.jpg" as JPEG 
end mouseup
the default folder can be set to any valid path.

bogs
Posts: 5435
Joined: Sat Feb 25, 2017 10:45 pm

Re: Export snapshot of group to jpg

Post by bogs » Mon Oct 29, 2018 10:19 pm

ClipArtGuy wrote:
Mon Oct 29, 2018 5:51 pm
the default folder can be set to any valid path.
As an addendum to ClipArtGuy's addendum of bog's addendum to Klaus's notes, it should be noted that the above *could* cause problems on a Mac (and possibly other OSes) where, as Klaus noted, the default folder could be inside of an application bundle. OSX treats these as folders as far as paths are concerned, but you often don't have write/read permission inside of one as they are also treated as monolithic apps :wink:
Image

Post Reply

Return to “Getting Started with LiveCode - Complete Beginners”