I am somewhat of a beginner and suspect that this topic may have been dealt with before. My apologies. I have read guides and various help sources but still can’t make this code work. There must be something simple I am missing.
// to save a picture file “pictureresult” (stored as a constant in module1) in an external file
// after storing this picture in “pictureresult” in earlier code it is displayed in an image well to show that it holds the picture
// this code is in the action event handler of a button
dim pic1 as picture
dim f As FolderItem
pic1 = module1.pictureresult
If pic1 <> Nil Then
If pic1.IsExportFormatSupported(Picture.FormatPNG) then
f = getfolderitem("desktopfolder.picresults") // Get a temporary file to save the image to
window1.listbox1.addrow(f.name) // just to see what f is
pic1.save(f, picture.SaveAsPNG) // save the image in the file
end If
you dont say if there is an error or what the problem is.
My guess is that you cant find the file, or that you get an error trying to save it (because it will be trying to save in the application folder using this code)
The problem would be this line:
f = getfolderitem("desktopfolder.picresults")
try changing it to
f = specialfolder.desktop.child("picresults.png")
if there are other problems, tell us which line causes an error.
I’m guessing your expecting to see a directory (folder) on your desktop call picresults and thats not happening ?
And that you want the picture to show up inside that directory ?
try
dim pic1 as picture
dim dirToSaveIn As FolderItem
dim fileToSaveInto as FolderItem
pic1 = module1.pictureresult
If pic1 <> Nil Then
If pic1.IsExportFormatSupported(Picture.FormatPNG) then
dirToSaveIn = specialFolder.desktopfolder.child("picresults") // <<<<<<<<<<<<<<<<<<<<< the DIR TO save into
if dirToSaveIn = nil then
// OH OH this is a big problem but could happen if you have no permissions !
break // YOU need to figure out what to do
return // but you should NOT proceed to try & do anything more !
elseif dirToSaveIn.exists = false then
dirToSaveIn.createAsFolder() // if it doesn't exist you have to create it
end if
fileToSaveInto = dirToSaveIn.child("some picture name here") // <<<<<<<<<<<< this is the FILE your picture would be saved in
window1.listbox1.addrow(fileToSaveInto.name ) // just to see what f is
pic1.save(fileToSaveInto, picture.SaveAsPNG) // save the image in the file
end If
end if
Thank you Geoff and Norman. The problem is that no external file which I expect to see appears. I will try your suggestions and come back to you. Thanks again.
I have tried your solution and after a little adjustment brought up by the debug process it works! I had to change “desktopfolder” to “desktop” and then it ran and produced a file called “some picture name here” ! with the correct picture in it. I will sort out the naming process later. I am very grateful for your help. The way in which you split up the process into separate steps helps to make it all clearer. Cheers.