smithmrk
asked on
Get the Length of an Image Created using Memory Stream
Hello Experts!
OK, so I need to get the Length of an Image created from a Memory Stream:
Dim memstrm As IO.MemoryStream = New IO.MemoryStream
Dim ticket As New Bitmap(1312, 574)
Dim ticketGraphics As Graphics = Graphics.FromImage(ticket)
ticketGraphics.FillRectang le(Brushes .White, 0, 0, 1312, 574)
ticket.Save(memstrm, System.Drawing.Imaging.Ima geFormat.T iff)
When I do memstrm.Length this is NOT the Length I need.
The Length I need is 14584
I get the 14584 when I open the file using a FileStream...but how can I get this length so I don't have to save the file then open again?
Mark
OK, so I need to get the Length of an Image created from a Memory Stream:
Dim memstrm As IO.MemoryStream = New IO.MemoryStream
Dim ticket As New Bitmap(1312, 574)
Dim ticketGraphics As Graphics = Graphics.FromImage(ticket)
ticketGraphics.FillRectang
ticket.Save(memstrm, System.Drawing.Imaging.Ima
When I do memstrm.Length this is NOT the Length I need.
The Length I need is 14584
I get the 14584 when I open the file using a FileStream...but how can I get this length so I don't have to save the file then open again?
Mark
ASKER
I just tried the Flush that didn't seem to work.
I'm getting 50168
Mark
I'm getting 50168
Mark
Is there something that your are not showing us. The following gives me exactly the same reading, 4926 and 4926:
Dim memstrm As IO.MemoryStream = New IO.MemoryStream
Dim filestrm As IO.FileStream = New IO.FileStream(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) & "\Test.tiff", FileMode.Create)
Dim ticket As New Bitmap(1312, 574)
Dim ticketGraphics As Graphics = Graphics.FromImage(ticket)
ticketGraphics.FillRectangle(Brushes.White, 0, 0, 1312, 574)
ticket.Save(memstrm, System.Drawing.Imaging.ImageFormat.Tiff)
ticket.Save(filestrm, Imaging.ImageFormat.Tiff)
filestrm.Close()
Debug.WriteLine(memstrm.Length)
Debug.WriteLine(New IO.FileInfo(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) & "\Test.tiff").Length)
memstrm.Close()
ASKER
Do it this way and you will see what I mean:
Private Sub Test()
Dim memstrm As IO.MemoryStream = New IO.MemoryStream
Dim ticket As New Bitmap(1312, 574)
Dim ticketGraphics As Graphics = Graphics.FromImage(ticket)
ticketGraphics.FillRectang le(Brushes .White, 0, 0, 1312, 574)
ticket.Save(memstrm, System.Drawing.Imaging.Ima geFormat.T iff)
ticket.Save("C:\Images\Mar k.tif")
MessageBox.Show(memstrm.Le ngth)
MessageBox.Show(New IO.FileStream("C:\Images\M ark.tif", IO.FileMode.Open).Length)
End Sub
Mark
Private Sub Test()
Dim memstrm As IO.MemoryStream = New IO.MemoryStream
Dim ticket As New Bitmap(1312, 574)
Dim ticketGraphics As Graphics = Graphics.FromImage(ticket)
ticketGraphics.FillRectang
ticket.Save(memstrm, System.Drawing.Imaging.Ima
ticket.Save("C:\Images\Mar
MessageBox.Show(memstrm.Le
MessageBox.Show(New IO.FileStream("C:\Images\M
End Sub
Mark
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
OK, so I can't get the 14584 Length unless I save it?
I don't want to have to save it open it get the 14584 then close it and delete it.
That is a lot of steps just to get the 14584 number.
I'm creating images on the fly and need to save them all in a Stacked Image when done.
Once the Stacked Image is done I will have an XML file with all the offsets and lengths to find the image with in the stacked image.
I don't want to have to write out a bunch images then loop through them all to get the lenghts and create a stacked image from all the indivdual images, then delete them all.
Mark
I don't want to have to save it open it get the 14584 then close it and delete it.
That is a lot of steps just to get the 14584 number.
I'm creating images on the fly and need to save them all in a Stacked Image when done.
Once the Stacked Image is done I will have an XML file with all the offsets and lengths to find the image with in the stacked image.
I don't want to have to write out a bunch images then loop through them all to get the lenghts and create a stacked image from all the indivdual images, then delete them all.
Mark
ASKER
OK, I figured it out!
Thanks,
Mark
Thanks,
Mark
You may need to call the Flush() method before requesting the length.