By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
454,703 Members | 1,400 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 454,703 IT Pros & Developers. It's quick & easy.

Saving Images to Files (& Related Questions)

P: n/a
I'm relatively new to using FileStreams, so bear with me.

I'm trying to use the following code

Dim MapGraphicsFileStream As New System.IO.FileStream(MapGraphicsFile,
System.IO.FileMode.Create)
Dim MapGraphicsFileStreamWriter As New System.IO.BinaryWriter
(MapGraphicsFileStream)
Dim A As Integer
For A = 0 To MapGraphics.GetUpperBound(0)
MapGraphics(A).MapBitmap.Save(MapGraphicsFileStrea m,
System.Drawing.Imaging.ImageFormat.Bmp)
MapGraphicsFileStreamWriter.Write(MapGraphics
(A).DefaultProperties.Role)
Next
MapGraphicsFileStream.Close()
MapGraphicsFileStreamWriter.Close()
End

to write a series of System.Drawing.Images and associated properties
(currently one integer, but eventually far more extensive) to a datafile.

I read it during the next program session using a procedure that I judge
to be a rough inverse of the routine I use to write the data.

Dim MapGraphicsFileStream As New System.IO.FileStream(MapGraphicsFile,
System.IO.FileMode.Open)
Dim MapGraphicsFileStreamReader As New System.IO.BinaryReader
(MapGraphicsFileStream)
Dim A As Integer
For A = 0 To 1
MapGraphics(A) = New MapGraphicsTemplate
MapGraphics(A).MapBitmap = System.Drawing.Image.FromStream
(MapGraphicsFileStream)
MapGraphics(A).DefaultProperties.Role =
MapGraphicsFileStreamReader.ReadInt32
Next
MapGraphicsFileStream.Close()
MapGraphicsFileStreamReader.Close()

Only it doesn't work... while MapGraphic(A).DefaultProperties.Role seems
to write/read correctly across program sessions, both images read as
slightly corrupted versions of the image I selected for MapGraphic
(1).MapBitmap

Can anybody give me a simply-worded (since I am a FileStream beginner!)
explanation of where I went wrong and whereabouts the correct track might
lie?

Further, you'll notice that while For A = 0 To MapGraphics.GetUpperBound
(0) gets the number of iterations necessary to *write* all populated data
in the MapGraphics array, I have no equivalent for the reader.

My thanks for any help you can provide.
Feb 17 '06 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.