0

Please help me in fixing my problem in saving the resized image. Here is the code:

protected void Resize(object sender, EventArgs e)
{
    img3.Src = img1.Src;

    img3.Width = Int32.Parse(imgWidth.Text);
    img3.Height = Int32.Parse(imgHeight.Text);

    Bitmap b = new Bitmap(Int32.Parse(imgWidth.Text), Int32.Parse(imgHeight.Text));
    Graphics gr = Graphics.FromImage(b);

    b.Save(Server.MapPath(img1.Src + "resized.png"));
}
Jérémie Bertrand
  • 3,025
  • 3
  • 44
  • 53
H.A.M
  • 51
  • 7

1 Answers1

0

The following line:

Bitmap b = new Bitmap(Int32.Parse(imgWidth.Text),Int32.Parse(imgHeight.Text));

Constructs an empty image with the selected width and height. You should use the Bitmap costructor that takes an image and Size parameter

Bitmap b = new Bitmap(yourImage, new Size(yourWidth, yourheight));

If you want a high quality resize, check out this answer here:

Resize an image C#

Community
  • 1
  • 1
Vect0rZ
  • 401
  • 2
  • 6