Problem Saving Image In Windows

Hi,

I have a weird problem I can’t figure out. I’m trying to save an image displayed on a Canvas to a jpg file. My code on a Mac works fine and saves the file without a problem. But on Windows it throws an exception that says “f” is nil. Here is the code:

Dim f as FolderItem DIM File1 AS String = "Map" + ".jpg" txtMap.Text=File1 f = getfolderitem("").child("Images").child(File1) Dim pic2 As New Picture(Canvas1.Width, Canvas1.Height, 32) Canvas1.DrawInto(pic2.Graphics, 0, 0) pic2.Save(f, Picture.SaveAsJPEG) //Throws error here.

If I replace

 f = getfolderitem("").child("Images").child(File1)

with

f = SpecialFolder.Documents.Child("MyFolder").Child("MySubFolder").Child("Images").Child( File1 )

The file is saved without a problem. But I want the image to be saved in the Images folder and not the Documents folder.

Why does it work on a Mac and not on Windows? Seems pretty straight forward. Can anyone see what may be the problem? Any help would be appreciated.

Are you having problems on a compiled App, or under the Debugger?

I have the following conditional compilation settings for some of my apps.

#IF DebugBuild then // f = GetFolderItem("").Parent #ELSE f = GetFolderItem("") #ENDIF

That was it. Thanks so much Langue. I appreciate it. Its working correctly now.

Thanks again.

Tries to write a file into a folder that it in the same location as the app.
On Windows, that would mean writing a file into a sub folder of Program Files, which is a nono unless you run with elevated permissions.

Your actual problem is probably the one mentioned above… a difference between the folder layout of debug and release builds.
The images folder will be missing from the debug build folder.

On Mac and Windows, do this:

At startup, check for the existence of
Specialfolder.Applicationdata.child(“MYAPP”) folder
If it is not there, create it

then check for the existence of
Specialfolder.Applicationdata.child(“MYAPP”) .child(“images”)
If it is not there, create it

Then there will be a folder
Specialfolder.Applicationdata.child(“MYAPP”) .child(“images”)

to hold your image when you are ready to save it

Thanks Jeff. Langue’s solution fixed the problem. I forgot about that.

As far as writing to a Windows folder, my software installs in the Users/Public folder. That way I don’t have any problems writing to it like I would if it were in the Program Files folder.

Thanks for your help.