拉伸图像,不拉伸绘图
Stretching image, without stretching drawing
我有一个 200x200 的图片框,它有一个 100x100 的图像,我使用 pictureBox.SizeMode = PictureBoxSizeMode.StretchImage;
对其进行了拉伸。之后我想在上面画一张 50x50 的图片,但不要拉伸它。
我正在使用这段代码,但它仍然会拉伸 50x50 图像:
//setting the pictureBoxes image
pictureBox.Image = (Image)Properties.Resources.ResourceManager.GetObject("100x100_Image");
pictureBox.SizeMode = PictureBoxSizeMode.StretchImage;
//drawing the second image
Point x = new Point(0, 0);
Bitmap bmp = new Bitmap(pictureBox.Image);
Graphics g = Graphics.FromImage(bmp);
g.DrawImage(new Bitmap((Image)Properties.Resources.ResourceManager.GetObject("50x50_Image")), x);
pictureBox.Image = bmp;
使用PictureBox的Paint事件:
private void PictureBox1_Paint(object sender, PaintEventArgs e) {
var bmp50 = Properties.Resources._50x50_Image;
e.Graphics.DrawImage(bmp50, new Point(0, 0));
}
我有一个 200x200 的图片框,它有一个 100x100 的图像,我使用 pictureBox.SizeMode = PictureBoxSizeMode.StretchImage;
对其进行了拉伸。之后我想在上面画一张 50x50 的图片,但不要拉伸它。
我正在使用这段代码,但它仍然会拉伸 50x50 图像:
//setting the pictureBoxes image
pictureBox.Image = (Image)Properties.Resources.ResourceManager.GetObject("100x100_Image");
pictureBox.SizeMode = PictureBoxSizeMode.StretchImage;
//drawing the second image
Point x = new Point(0, 0);
Bitmap bmp = new Bitmap(pictureBox.Image);
Graphics g = Graphics.FromImage(bmp);
g.DrawImage(new Bitmap((Image)Properties.Resources.ResourceManager.GetObject("50x50_Image")), x);
pictureBox.Image = bmp;
使用PictureBox的Paint事件:
private void PictureBox1_Paint(object sender, PaintEventArgs e) {
var bmp50 = Properties.Resources._50x50_Image;
e.Graphics.DrawImage(bmp50, new Point(0, 0));
}