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