Page 1 of 1
Export snapshot of group to jpg
Posted: Mon Oct 29, 2018 1:17 pm
by propeller
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!
Re: Export snapshot of group to jpg
Posted: Mon Oct 29, 2018 1:37 pm
by Klaus
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!
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
Re: Export snapshot of group to jpg
Posted: Mon Oct 29, 2018 2:22 pm
by propeller
Dear Klaus,
thank you for your answer. this did the trick. you are great!
Have a nice day.
Re: Export snapshot of group to jpg
Posted: Mon Oct 29, 2018 5:09 pm
by bogs
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 -
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.

- Message Box...
- Selection_079.png (11.41 KiB) Viewed 5178 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 -

- Answer Folder dialog...
Re: Export snapshot of group to jpg
Posted: Mon Oct 29, 2018 5:12 pm
by propeller
dear bogs!
thank you for sharing. this is helpful.

Re: Export snapshot of group to jpg
Posted: Mon Oct 29, 2018 5:51 pm
by ClipArtGuy
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.
Re: Export snapshot of group to jpg
Posted: Mon Oct 29, 2018 10:19 pm
by bogs
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
