I'm trying to resize the image to fit the PictureBox size but it's not working.
I added a method resizeImage
but no matter what size I give the result is the same.
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void pictureBox1_Paint(object sender, PaintEventArgs e)
{
Bitmap myBitmap = CreateNonIndexedImage(new Bitmap(@"d:\drawplane1.jpg"));
resizeImage(myBitmap, new Size(1, 1));
// Draw myBitmap to the screen.
e.Graphics.DrawImage(myBitmap, 0, 0, myBitmap.Width,
myBitmap.Height);
// Set each pixel in myBitmap to black.
for (int Xcount = 0; Xcount < myBitmap.Width; Xcount++)
{
for (int Ycount = 0; Ycount < myBitmap.Height; Ycount++)
{
myBitmap.SetPixel(Xcount, Ycount, Color.Black);
}
}
// Draw myBitmap to the screen again.
e.Graphics.DrawImage(myBitmap, myBitmap.Width, 0,
myBitmap.Width, myBitmap.Height);
}
public Bitmap CreateNonIndexedImage(Image src)
{
Bitmap newBmp = new Bitmap(src.Width, src.Height, System.Drawing.Imaging.PixelFormat.Format32bppArgb);
using (Graphics gfx = Graphics.FromImage(newBmp))
{
gfx.DrawImage(src, 0, 0);
}
return newBmp;
}
public static Image resizeImage(Image imgToResize, Size size)
{
return (Image)(new Bitmap(imgToResize, size));
}
}
No mater what size I put in the line:
resizeImage(myBitmap, new Size(1, 1));
..the image is too big inside the pictureBox:
I tried 10,10
then 1,1
for testing but it's not changing the image size.
This is the original image :
Original image file : https://i.stack.imgur.com/6uFMo.jpg