if its stored in sql server it will be stored as byte arry.. so read it into
a byte array.. attached find a piece of c# code that just does that.
use equivalent vb.net calls
private void WriteImage(ref byte[] ImageData, ref HttpContext context,
ImageType imgType, string cacheKey)
{
System.Drawing.Image myImage = null;
MemoryStream myStream = new MemoryStream();
MemoryStream processedMemStream = new MemoryStream();
try
{
myStream.Write(ImageData, 0, ImageData.Length);
myImage = System.Drawing.Image.FromStream(myStream);
int imageWidth = myImage.Width;
int imageHeight = myImage.Height;
int processedHeight;
if(imgType == ImageType.Full)
{
processedHeight = imageWidth;
}
else
{
processedHeight = (int)imgType;
}
double multiplicationFactor =
(double)processedHeight/(double)imageHeight;
int processedWidth = (int)( (double)imageWidth * multiplicationFactor);
Bitmap processedBP = new Bitmap(processedWidth, processedHeight);
Graphics g = Graphics.FromImage(processedBP);
try
{
g.SmoothingMode =SmoothingMode.HighQuality;
g.InterpolationMode =InterpolationMode.HighQualityBicubic;
g.PixelOffsetMode =PixelOffsetMode.HighQuality;
Rectangle rect=new Rectangle(0,0,processedWidth,processedHeight);
//Draw the old image on to the new image using the graphics object:
g.DrawImage(myImage,rect,0,0,myImage.Width,myImage .Height,GraphicsUnit.Pixel
);
processedBP.RotateFlip(RotateFlipType.Rotate180Fli pNone);
processedBP.RotateFlip(RotateFlipType.Rotate180Fli pNone);
processedBP.Save(processedMemStream, ImageFormat.Jpeg);
byte[] processedImageData = processedMemStream.ToArray();
if(processedImageData != null)
{
context.Cache.Add(cacheKey, processedImageData, null,
Cache.NoAbsoluteExpiration, TimeSpan.FromMinutes(10),
CacheItemPriority.Normal, new
CacheItemRemovedCallback(this.RemovedCallback));
context.Response.BinaryWrite(processedImageData);
processedImageData = null;
}
}
finally
{
g.Dispose();
processedBP.Dispose();
}
}
finally
{
processedMemStream.Close();
myStream.Close();
myImage.Dispose();
}
}
--
Regards,
Hermit Dave
(
http://hdave.blogspot.com)
"Robson Carvalho Machado" <Ro*******************@discussions.microsoft.com >
wrote in message news:05**********************************@microsof t.com...
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(FromF ile))
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.HorizontalResolutio n,
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.HighQualityBic ubic
' 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