Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

resizing images

Status
Not open for further replies.

mjd3000

Programmer
Apr 11, 2009
136
GB
I am displaying images from a database using the code below.

Is there any way I can resize the images before rendering them?



public void showSelectedImage(string strEncodedImage)
{
Response.Clear();
Response.ContentType = "image/jpeg";

System.Drawing.Image image = retrieveImage(strEncodedImage);
image.Save(Response.OutputStream, System.Drawing.Imaging.ImageFormat.Jpeg);
}

private System.Drawing.Image retrieveImage(string strEncodedImage)
{
System.Drawing.Image image = null;

byte[] imageData = Convert.FromBase64String(strEncodedImage);

MemoryStream memStream = new MemoryStream(imageData);
image = System.Drawing.Image.FromStream(memStream);

return image;
}
 
in retrieveImage, once yo have the full size image in memory, call the image.GetThumbnailImage() method, passing in the new size you want.

But dont forget that unless all your images are uniform in the database you may need to take into account the aspect ratios.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top