How to fit bitmap to the size of picture box in Winform C#
I have a picture box of size 492*522 (which is set in c# code)
But now the size of the picturebox reduces and it does not give a stretchable look. I want the size of the picture box to 492*522. itself. And should get a stretchable look when cropping 200 from bitmap.
How can I achieve this? Please help.
I have done it like below.
Rectangle section = new Rectangle(new Point(0, 200), new Size(image.Width / 2, image.Height));
FirstHalf = CropImage(FirstHalf, section);
pictureBox1.Image = FirstHalf;
public Bitmap CropImage(Bitmap source, Rectangle section)
{
var bitmap = new Bitmap(section.Width, section.Height);
using (var g = Graphics.FromImage(bitmap))
{
g.DrawImage(source, 0, 0, section, GraphicsUnit.Pixel);
return bitmap;
}
}