将图像转换为像素格式 - c#

时间:2011-09-01 08:40:18

标签: c# image format pixel

我的代码存在问题。我能够将图像转换为我想要的像素格式。但问题是,当我使用位图作为我的图片框时,它只是黑色。

sourceImage = new Bitmap(sourceImage.Width, sourceImage.Height,
System.Drawing.Imaging.PixelFormat.Format24bppRgb);

pictureBoxCurrency.Image = sourceImage;

1 个答案:

答案 0 :(得分:0)

您已经创建了新的位图,但是您需要将图像(传输)从原始图像(转移)绘制到新的位图。

Bitmap newBitmap = new Bitmap(sourceImage.Size.Width, sourceImage.Size.Height, System.Drawing.Imaging.PixelFormat.Format24bppRgb);
Graphics g = Graphics.FromImage(newBitmap);
g.DrawImage(sourceImage, new Point(0, 0));
g.Dispose();

pictureBoxCurrency.Image = sourceImage;
相关问题