G
Guest
Dear Friends,
Does anybody knows how to use the below code with an image stored at SQL
Image field?
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
ScaleStatic("/website/images/default_03.jpg", 50)
End Sub
Public Sub ScaleStatic(ByVal FromFile, ByVal intSize)
'Dim inputFile As New FileInfo(Server.MapPath(FromFile))
' Main bitmap/graphics "canvas". Change size to suit your needs
' load image
Dim imgPhoto As System.Drawing.Image =
System.Drawing.Image.FromFile(Server.MapPath(FromFile))
Dim sourceWidth As Integer = imgPhoto.Width
Dim sourceHeight As Integer = imgPhoto.Height
Dim sourceX As Integer = 0
Dim sourceY As Integer = 0
Dim destX As Integer = 0
Dim destY As Integer = 0
Dim destWidth As Integer = 0
Dim destHeight As Integer = 0
If imgPhoto.Width > imgPhoto.Height Then ' landscape-layout
' calculate new height
destHeight = ((intSize * 1.0 / sourceWidth) * sourceHeight)
destWidth = intSize
Else ' portrait-layout
destHeight = intSize
' calculate new width
destWidth = ((intSize * 1.0 / sourceHeight) * sourceWidth)
End If
Dim bmPhoto As Bitmap = New Bitmap(destWidth, destHeight,
imgPhoto.PixelFormat.Format24bppRgb)
bmPhoto.SetResolution(imgPhoto.HorizontalResolution,
imgPhoto.VerticalResolution)
Dim grPhoto As Graphics = Graphics.FromImage(bmPhoto)
grPhoto.CompositingQuality =
Drawing.Drawing2D.CompositingQuality.HighQuality
grPhoto.SmoothingMode = Drawing.Drawing2D.SmoothingMode.HighQuality
grPhoto.InterpolationMode =
Drawing.Drawing2D.InterpolationMode.HighQualityBicubic
' Draw onto canvas
grPhoto.DrawImage(imgPhoto, New Rectangle(destX, destY, destWidth,
destHeight), New Rectangle(sourceX, sourceY, sourceWidth, sourceHeight),
GraphicsUnit.Pixel)
' Stream to user
bmPhoto.Save(Response.OutputStream,
System.Drawing.Imaging.ImageFormat.Jpeg)
grPhoto.Dispose()
bmPhoto.Dispose()
End Sub
Does anybody knows how to use the below code with an image stored at SQL
Image field?
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
ScaleStatic("/website/images/default_03.jpg", 50)
End Sub
Public Sub ScaleStatic(ByVal FromFile, ByVal intSize)
'Dim inputFile As New FileInfo(Server.MapPath(FromFile))
' Main bitmap/graphics "canvas". Change size to suit your needs
' load image
Dim imgPhoto As System.Drawing.Image =
System.Drawing.Image.FromFile(Server.MapPath(FromFile))
Dim sourceWidth As Integer = imgPhoto.Width
Dim sourceHeight As Integer = imgPhoto.Height
Dim sourceX As Integer = 0
Dim sourceY As Integer = 0
Dim destX As Integer = 0
Dim destY As Integer = 0
Dim destWidth As Integer = 0
Dim destHeight As Integer = 0
If imgPhoto.Width > imgPhoto.Height Then ' landscape-layout
' calculate new height
destHeight = ((intSize * 1.0 / sourceWidth) * sourceHeight)
destWidth = intSize
Else ' portrait-layout
destHeight = intSize
' calculate new width
destWidth = ((intSize * 1.0 / sourceHeight) * sourceWidth)
End If
Dim bmPhoto As Bitmap = New Bitmap(destWidth, destHeight,
imgPhoto.PixelFormat.Format24bppRgb)
bmPhoto.SetResolution(imgPhoto.HorizontalResolution,
imgPhoto.VerticalResolution)
Dim grPhoto As Graphics = Graphics.FromImage(bmPhoto)
grPhoto.CompositingQuality =
Drawing.Drawing2D.CompositingQuality.HighQuality
grPhoto.SmoothingMode = Drawing.Drawing2D.SmoothingMode.HighQuality
grPhoto.InterpolationMode =
Drawing.Drawing2D.InterpolationMode.HighQualityBicubic
' Draw onto canvas
grPhoto.DrawImage(imgPhoto, New Rectangle(destX, destY, destWidth,
destHeight), New Rectangle(sourceX, sourceY, sourceWidth, sourceHeight),
GraphicsUnit.Pixel)
' Stream to user
bmPhoto.Save(Response.OutputStream,
System.Drawing.Imaging.ImageFormat.Jpeg)
grPhoto.Dispose()
bmPhoto.Dispose()
End Sub