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;
}
The recommended way to write it would be:
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;
}
来源:https://stackoverflow.com/questions/24620464/how-to-draw-an-image-onto-a-picturebox-image