0

I have the problem setting the size of an Image to a maximum value. Do you have a code example how to set the Image Size ?

System.Drawing.Image image = System.Drawing.Image.FromStream(stream, true);

In the first step I am loading the image from Stream and in the next step i want to set the image.Site.width to 800

Uwe Keim
  • 39,551
  • 56
  • 175
  • 291
user3929884
  • 213
  • 6
  • 15

1 Answers1

1

You can resize the image by creating a new Image from it and specifying the size:

System.Drawing.Image resizedImage = new Bitmap(image, new Size(100,100));

If you want more control over the resize, you can draw it to a new image and set the interpolation mode:

System.Drawing.Image resizedImage = new Bitmap(100,100);

using (Graphics graphicsHandle = Graphics.FromImage(resizedImage))
{
    graphicsHandle.InterpolationMode = InterpolationMode.HighQualityBicubic;
    graphicsHandle.DrawImage(image, 0, 0, 100, 100);
}
return resizedImage;
John Koerner
  • 37,428
  • 8
  • 84
  • 134