0

我试图使用 Graphics.DrawImage 但我得到黑色图像并且在它上面画了红点。为什么我得到黑色图像?

这是功能:

public Bitmap SaveFromPictureBoxToBitMap(Bitmap image1, Image pbox)
        {

            Graphics g = Graphics.FromImage(image1);
            Point p = new Point(pbox.Width,pbox.Height);
            g.DrawImage(pbox, p);
            image1.Save(@"d:\PictureBoxToBitmap\ptob.bmp", System.Drawing.Imaging.ImageFormat.Bmp);
            return newImage;
        }

image1 是我在绘画事件中绘制的 bmp 变量。而 pbox 只是 pictureBox1.Image 并且我在 trackBar1 滚动事件中使用了这个函数。

这就是我在这里添加屏幕截图的原因:

在此处输入图像描述

在背景上而不是黑色我需要从 pictureBox1 获取图像,但它不起作用,为什么?

4

1 回答 1

0

找到了:

using (Bitmap b = new Bitmap(pictureBox1.Width, pictureBox1.Height))
{
    pictureBox1.DrawToBitmap(b, new Rectangle(0, 0, pictureBox1.Width, pictureBox1.Height));
    b.Save(@"d:\testit.png", System.Drawing.Imaging.ImageFormat.Png);
} 
于 2012-07-01T18:47:46.393 回答