Write picture to file

I have made a file that writes a text to a certain file. How could a write a picture or any other data type to the file?

Thanks

The Xojo docs have this:
http://documentation.xojo.com/index.php/Picture.Save

[quote=48430:@Jeff Tullin]The Xojo docs have this:
http://documentation.xojo.com/index.php/Picture.Save[/quote]
Doesn’t this just replace the contents of the file rather than adding to it?

Thanks

Yes it does.
This requirement wasn’t clear from your question.

In your shoes I might the picture data to a string, and write that.

The tricky part comes in reading it BACK into memory and making it a picture again.
It’s up to you how to determine where the text you wrote first ends, and the picture data starts/ends.
Thats probably where a structured text format like XML comes to your aid.

Heres some old code from Tom Mgrath:

Picture to String

Dim P As New Picture(32,32,32) Dim M As MemoryBlock = P.GetData(Picture.FormatJPEG) Dim S As String = M
String to Picture

Dim M As MemoryBlock = "some jpeg data" Dim P As Picture = Picture.FromData(M)
Note that “some jpeg data” isn’t really JPEG data and won’t work, but you get the idea.

[quote=48439:@Jeff Tullin]Yes it does.
This requirement wasn’t clear from your question.

In your shoes I might the picture data to a string, and write that.

The tricky part comes in reading it BACK into memory and making it a picture again.
It’s up to you how to determine where the text you wrote first ends, and the picture data starts/ends.
Thats probably where a structured text format like XML comes to your aid.

Heres some old code from Tom Mgrath:

Picture to String

Dim P As New Picture(32,32,32) Dim M As MemoryBlock = P.GetData(Picture.FormatJPEG) Dim S As String = M
String to Picture

Dim M As MemoryBlock = "some jpeg data" Dim P As Picture = Picture.FromData(M)
Note that “some jpeg data” isn’t really JPEG data and won’t work, but you get the idea.[/quote]
Thanks!! If this works then this is excellent and exactly what I was looking for. And my project is structured in an XML file.

FUNCTION PictureToString(p as picture) as string
  '// Convert a picture to a String 
  If p=Nil Then Return ""
  Return EncodeBase64(p.GetData(Picture.FormatPNG),0)
END FUNCTION

FUNCTION StringToPicture(data as string) as picture
  '// Convert a String to a picture
  Dim p As picture
  If data="" Then Return Nil
  p=picture.FromData(DecodeBase64(data))
  p.transparent=1
  Return p
END FUNCTION

Base64 if used to insure there is only “safe” characters so it can be stored as “normal” text without any concerns

[quote=48450:@Dave S][code]
FUNCTION PictureToString(p as picture) as string
'// Convert a picture to a String
If p=Nil Then Return “”
Return EncodeBase64(p.GetData(Picture.FormatPNG),0)
END FUNCTION

FUNCTION StringToPicture(data as string) as picture
'// Convert a String to a picture
Dim p As picture
If data="" Then Return Nil
p=picture.FromData(DecodeBase64(data))
p.transparent=1
Return p
END FUNCTION
[/code]

Base64 if used to insure there is only “safe” characters so it can be stored as “normal” text without any concerns[/quote]
Thanks. Sounds good.

FYI… you may or may not want to keep the p.transparent=1 line… depends on what you are going to do with the picture