User2098176964 posted
I need to convert Byte to stream and save it to db field type image
Protected Function Resize(ByVal strThumb As String) As Byte
Dim objImage As System.Drawing.Image
Dim intWidth As Integer
Dim intHeight As Integer
Dim TimesTwo As Double
Dim x As Integer
Dim y As Integer
If IO.File.Exists(strThumb) Then
objImage = Drawing.Image.FromFile(strThumb)
intWidth = objImage.Width
intHeight = objImage.Height
If intHeight > intWidth Then ' portrait
TimesTwo = 400 / intHeight
Else
TimesTwo = 400 / intWidth
End If
x = CInt(intWidth * TimesTwo)
y = CInt(intHeight * TimesTwo)
Dim thumb As New Bitmap(objImage, x, y)
Dim graphics As Graphics = graphics.FromImage(thumb)
graphics.InterpolationMode = Drawing2D.InterpolationMode.HighQualityBicubic
graphics.SmoothingMode = SmoothingMode.HighQuality
graphics.DrawImage(thumb, New Rectangle(0, 0, x, y), New Rectangle(0, 0, thumb.Width, thumb.Height), GraphicsUnit.Pixel)
graphics.Dispose()
'Write out the image in browser, so for so good
Response.ContentType = "image/jpeg"
thumb.Save(Response.OutputStream, ImageFormat.Jpeg)
'Make the image av Stream and insert it to db
Dim imgStream As New IO.MemoryStream
thumb.Save(imgStream, ImageFormat.Jpeg)
Dim c(imgStream.Length() - 1) As Byte
imgStream.Read(c, 0, c.Length)
imgStream.Close()
How can I pass the value with stream to db
'If I want to save it to file
'thumb.Save(Server.MapPath("minFIl.jpg"), ImageFormat.Jpeg)
thumb.Dispose()
objImage.Dispose()
IO.File.Delete(strThumb)
End If
End Function