0
我相對較新的圖像處理在C#中。我試圖在一個圖片框中縮放這個動態構造的BMP,但圖像沒有被調整大小。我想要BMP來填充整個圖片框。圖片框是555 x 555.它只是顯示了原始大小(100 x 100)的BMP。有任何想法嗎?爲什麼圖像沒有在圖片框中拉伸?
private void Form1_Load(object sender, EventArgs e)
{
pictureBox1.SizeMode = PictureBoxSizeMode.StretchImage;
}
private void pictureBox1_Paint(object sender, PaintEventArgs e)
{
Graphics gPB = e.Graphics;
Bitmap bmp = new Bitmap(100, 100);
Graphics gBmp = Graphics.FromImage(bmp);
Brush whiteBrush = new SolidBrush(Color.White);
gBmp.FillRectangle(whiteBrush, 0, 0, bmp.Width, bmp.Height);
Brush redBrush = new SolidBrush(Color.IndianRed);
gBmp.FillRectangle(redBrush, 0, 0, 20f, 20f);
Brush greenBrush = new SolidBrush(Color.MediumSeaGreen);
gBmp.FillRectangle(greenBrush, 20, 0, 20f, 20f);
Brush blueBrush = new SolidBrush(Color.MediumSlateBlue);
gBmp.FillRectangle(blueBrush, 0, 20, 20f, 20f);
Brush yellowBrush = new SolidBrush(Color.LightYellow);
gBmp.FillRectangle(yellowBrush, 20, 20, 20f, 20f);
gPB.DrawImage(bmp, 0, 0, bmp.Width, bmp.Height);
pictureBox1.SizeMode = PictureBoxSizeMode.StretchImage;
}
我也試過Zoom SizeMode。這沒有任何區別。
有趣。繪製圖像時,我從來沒有想過要使用pictureBox的寬度和高度。插值模式有助於調整大小後的分辨率。這正是我想要的! – deutschZuid