如何在PictureBox图像上绘制图像 [英] How to draw an image onto a PictureBox Image
本文介绍了如何在PictureBox图像上绘制图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要知道如何在PictureBox的图像上绘制多个图像.
I need to know how to draw more than one Image on a PictureBox's Image.
我已经使用了这段代码,但是它不起作用:
I have used this code but it doesn't work:
private void button3_Click(object sender, EventArgs e)
{
Bitmap bmp = new Bitmap(pictureBox2.Image);
Graphics g = Graphics.FromImage(bmp);
g.DrawImage(new Bitmap(@"C:\Users\Mena\Desktop\1.png"), new Point(182, 213));
pictureBox2.Image = bmp;
}
推荐答案
稍作更改,您的代码就可以正常工作:
With a few changes your code will work fine:
private void button3_Click(object sender, EventArgs e)
{
Bitmap bmp = new Bitmap(pictureBox2.Image);
// whatever your plans where, we don't know ;-)
// RectangleF rectf = new RectangleF(640F, 1100F, 0, 0);
Graphics g = Graphics.FromImage(bmp);
// DrawImage needs an image, not a string
g.DrawImage(new Bitmap(@"C:\Users\Mena\Desktop\1.png"), new Point(182, 213));
// flush is for finishing write operations
// dispose is the command to get rid of GDI elements:
g.Dispose();
pictureBox2.Image = bmp;
}
推荐的编写方式为:
private void button3_Click(object sender, EventArgs e)
{
Bitmap bmp = new Bitmap(pictureBox2.Image);
using (Graphics g = Graphics.FromImage(bmp))
{
g.DrawImage(new Bitmap((@"C:\Users\Mena\Desktop\1.png"), new Point(182, 213));
}
pictureBox2.Image = bmp;
}
这篇关于如何在PictureBox图像上绘制图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文