i am changing size of imge with dimension given by textbox.
-
i used this code but my picturebox is changing value but my image in not fitting in that picturebox.. it comes half or first quadrant etc. so please help me in this private void Calculate_btn_Click(object sender, EventArgs e) { Bitmap sourceimage = (Bitmap)pictureBox2.Image.Clone(); int height = sourceimage.Size.Height; int width = sourceimage.Size.Width; float nPercent = 0; float nPercentW = 0; float nPercentH = 0; int newheight = Convert.ToInt32(height_txt.Text); int newwidth = Convert.ToInt32(width_txt.Text); nPercentW = ((float)newheight / (float)height); nPercentH = ((float)newwidth / (float)width); if (nPercentH < nPercentW) nPercent = nPercentH; else nPercent = nPercentW; int destWidth = (int)(width * nPercent); int destHeight = (int)(height * nPercent); Bitmap b = new Bitmap(destWidth, destHeight); Graphics g = Graphics.FromImage((Image)b); g.DrawImage(sourceimage, 0, 0, destWidth, destHeight); pictureBox3.Image = sourceimage; pictureBox3.SizeMode = PictureBoxSizeMode.StretchImage;