P
Phil Jones
I'm having problem manipulating a file stream. What I'm doing (simplified
into a sample below) is opening a JPG file as a stream, and then saving it's
contents in a DB. However I seem to be munching the data somehow, because
if I try and save the file from the stream data, the JPG isn't readable.
Here's an example of the code I'm using, that appears to munch the file:
====================
REM -- Open an image.
Dim myImage As New FileStream("C:\TEMP\MyImage.jpg", FileMode.Open)
REM -- Copy to a stream.
Dim buffer(CInt(myImage.Length)) As Byte
myImage.Read(buffer, 0, buffer.Length)
Dim newStream As New MemoryStream(buffer)
REM -- Save stream data to a new file.
Dim newFile As New FileStream("C:\TEMP\Copy.jpg", FileMode.CreateNew)
newStream.Write(buffer, 0, buffer.Length)
REM -- Finish up.
myImage.Close()
newFile.Close()
====================
What am I missing here? Am I screwing up the buffer sizes or something?
Thanks anyone!
into a sample below) is opening a JPG file as a stream, and then saving it's
contents in a DB. However I seem to be munching the data somehow, because
if I try and save the file from the stream data, the JPG isn't readable.
Here's an example of the code I'm using, that appears to munch the file:
====================
REM -- Open an image.
Dim myImage As New FileStream("C:\TEMP\MyImage.jpg", FileMode.Open)
REM -- Copy to a stream.
Dim buffer(CInt(myImage.Length)) As Byte
myImage.Read(buffer, 0, buffer.Length)
Dim newStream As New MemoryStream(buffer)
REM -- Save stream data to a new file.
Dim newFile As New FileStream("C:\TEMP\Copy.jpg", FileMode.CreateNew)
newStream.Write(buffer, 0, buffer.Length)
REM -- Finish up.
myImage.Close()
newFile.Close()
====================
What am I missing here? Am I screwing up the buffer sizes or something?
Thanks anyone!