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 processedMemStr eam = new MemoryStream();
try
{
myStream.Write( ImageData, 0, ImageData.Lengt h);
myImage = System.Drawing. Image.FromStrea m(myStream);
int imageWidth = myImage.Width;
int imageHeight = myImage.Height;
int processedHeight ;
if(imgType == ImageType.Full)
{
processedHeight = imageWidth;
}
else
{
processedHeight = (int)imgType;
}
double multiplicationF actor =
(double)process edHeight/(double)imageHe ight;
int processedWidth = (int)( (double)imageWi dth * multiplicationF actor);
Bitmap processedBP = new Bitmap(processe dWidth, processedHeight );
Graphics g = Graphics.FromIm age(processedBP );
try
{
g.SmoothingMode =SmoothingMode. HighQuality;
g.Interpolation Mode =InterpolationM ode.HighQuality Bicubic;
g.PixelOffsetMo de =PixelOffsetMod e.HighQuality;
Rectangle rect=new Rectangle(0,0,p rocessedWidth,p rocessedHeight) ;
//Draw the old image on to the new image using the graphics object:
g.DrawImage(myI mage,rect,0,0,m yImage.Width,my Image.Height,Gr aphicsUnit.Pixe l
);
processedBP.Rot ateFlip(RotateF lipType.Rotate1 80FlipNone);
processedBP.Rot ateFlip(RotateF lipType.Rotate1 80FlipNone);
processedBP.Sav e(processedMemS tream, ImageFormat.Jpe g);
byte[] processedImageD ata = processedMemStr eam.ToArray();
if(processedIma geData != null)
{
context.Cache.A dd(cacheKey, processedImageD ata, null,
Cache.NoAbsolut eExpiration, TimeSpan.FromMi nutes(10),
CacheItemPriori ty.Normal, new
CacheItemRemove dCallback(this. RemovedCallback ));
context.Respons e.BinaryWrite(p rocessedImageDa ta);
processedImageD ata = null;
}
}
finally
{
g.Dispose();
processedBP.Dis pose();
}
}
finally
{
processedMemStr eam.Close();
myStream.Close( );
myImage.Dispose ();
}
}
--
Regards,
Hermit Dave
(
http://hdave.blogspot.com)
"Robson Carvalho Machado" <Ro************ *******@discuss ions.microsoft. com>
wrote in message news:05******** *************** ***********@mic rosoft.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.EventArg s) Handles MyBase.Load
ScaleStatic("/website/images/default_03.jpg" , 50)
End Sub
Public Sub ScaleStatic(ByV al FromFile, ByVal intSize)
'Dim inputFile As New FileInfo(Server .MapPath(FromFi le))
' 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(destWidt h, destHeight,
imgPhoto.PixelF ormat.Format24b ppRgb)
bmPhoto.SetReso lution(imgPhoto .HorizontalReso lution,
imgPhoto.Vertic alResolution)
Dim grPhoto As Graphics = Graphics.FromIm age(bmPhoto)
grPhoto.Composi tingQuality =
Drawing.Drawing 2D.CompositingQ uality.HighQual ity
grPhoto.Smoothi ngMode =
Drawing.Drawing 2D.SmoothingMod e.HighQuality grPhoto.Interpo lationMode =
Drawing.Drawing 2D.Interpolatio nMode.HighQuali tyBicubic
' Draw onto canvas
grPhoto.DrawIma ge(imgPhoto, New Rectangle(destX , destY, destWidth,
destHeight), New Rectangle(sourc eX, sourceY, sourceWidth, sourceHeight),
GraphicsUnit.Pi xel)
' Stream to user
bmPhoto.Save(Re sponse.OutputSt ream,
System.Drawing. Imaging.ImageFo rmat.Jpeg)
grPhoto.Dispose ()
bmPhoto.Dispose ()
End Sub