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

本文关键字:格式 像素 图像 转换 | 更新日期: 2023-09-27 18:07:17

我对下面的代码有一个问题。我能够将图像转换成我想要的像素格式。但问题是,当我为我的图片框使用位图时,它只是黑色的。

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

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

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

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;