How to draw an image onto a PictureBox Image [closed]

杀马特。学长 韩版系。学妹 提交于 2019-12-04 22:04:57

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;
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!