C
creepwood
I'm trying to load and image into a DB and alongside the image also a
thumbnailed version of the image, but somewhere in my code, the stream
doesn't take the thumbnail data. When I just change toe bitmap.save()
to a file instead of a stream it works just fine.
Dim bm As Bitmap = System.Drawing.Image.FromStream(fs)
Dim newHeight As Integer = 40
Dim newWidth As Integer = (newHeight / bm.Height) * bm.Width
Dim resized As Bitmap = New Bitmap(newWidth, newHeight)
Dim g As Graphics = Graphics.FromImage(resized)
g.InterpolationMode =
System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic
g.DrawImage(bm, New Rectangle(0, 0, resized.Width,
resized.Height), 0, 0, bm.Width, bm.Height, GraphicsUnit.Pixel)
g.Dispose()
'Problems starts here
Dim imgStream As New IO.MemoryStream
resized.Save(imgStream, ImageFormat.Jpeg)
Dim c(imgStream.Length() - 1) As Byte
imgStream.Read(c, 0, c.Length)
imgStream.Close()
'problems end here
somehere in between there something goes bad. and I don't know what.
the workaround is to save the img in a tempfile and read a stream from
that but that's absurd.
Please don't direct me to a guide, or suggest to me to rework my whole
code, I only need to get a filled stream.
/Bennie
thumbnailed version of the image, but somewhere in my code, the stream
doesn't take the thumbnail data. When I just change toe bitmap.save()
to a file instead of a stream it works just fine.
Dim bm As Bitmap = System.Drawing.Image.FromStream(fs)
Dim newHeight As Integer = 40
Dim newWidth As Integer = (newHeight / bm.Height) * bm.Width
Dim resized As Bitmap = New Bitmap(newWidth, newHeight)
Dim g As Graphics = Graphics.FromImage(resized)
g.InterpolationMode =
System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic
g.DrawImage(bm, New Rectangle(0, 0, resized.Width,
resized.Height), 0, 0, bm.Width, bm.Height, GraphicsUnit.Pixel)
g.Dispose()
'Problems starts here
Dim imgStream As New IO.MemoryStream
resized.Save(imgStream, ImageFormat.Jpeg)
Dim c(imgStream.Length() - 1) As Byte
imgStream.Read(c, 0, c.Length)
imgStream.Close()
'problems end here
somehere in between there something goes bad. and I don't know what.
the workaround is to save the img in a tempfile and read a stream from
that but that's absurd.
Please don't direct me to a guide, or suggest to me to rework my whole
code, I only need to get a filled stream.
/Bennie