当我使用以下代码将位图从 8bpp 转换为 24bpp 时,结果图像发生了移位,但我无法找出原因,有人可以帮忙吗?
private static Bitmap ConvertTo24(Bitmap bmpIn)
{
bmpIn.Save(@"F:\sara1.bmp");
Bitmap converted = new Bitmap(bmpIn.Width, bmpIn.Height, PixelFormat.Format24bppRgb);
using (Graphics g = Graphics.FromImage(converted))
{
// Prevent DPI conversion
g.PageUnit = GraphicsUnit.Pixel;
// Draw the image
g.DrawImageUnscaled(bmpIn, 0, 0);
// g.DrawImage(bmpIn, 0, 0);
}
converted.Save(@"F:\sara2.bmp");
}
最佳答案
以下代码对我有用:
private static Bitmap ConvertTo24(Bitmap bmpIn)
{
bmpIn.Save(@"F:\sara1.bmp");
Bitmap converted = new Bitmap(bmpIn.Width, bmpIn.Height, PixelFormat.Format24bppRgb);
using (Graphics g = Graphics.FromImage(converted))
{
// Prevent DPI conversion
g.PageUnit = GraphicsUnit.Pixel;
// Draw the image
// g.DrawImageUnscaled(bmpIn, 0, 0);
g.DrawImage(bmpIn, 0, 0, converted.Width, converted.Height);
}
converted.Save(@"F:\sara2.bmp");
}
提供宽度和高度可重新缩放图像。
关于c# - 8bpp 转换为 24bpp 时图像发生偏移,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13127171/