这是我的密码:
BitmapData bmpData = bitmap.LockBits(new Rectangle(0, 0, bitmap.Width, bitmap.Height), ImageLockMode.ReadWrite, PixelFormat.Format24bppRgb);
UnmanagedImage img = new UnmanagedImage(bmpData);
//MAIN BLOCK
BayerDithering filter = new BayerDithering();
img = new UnmanagedImage(img.ImageData, img.Width, img.Height, img.Stride, PixelFormat.Format8bppIndexed);
filter.ApplyInPlace(img);
//END MAIN BLOCK
bitmap.UnlockBits(bmpData);这是结果:屏幕截图
为什么结果不是合二为一的?我必须在“主块”中只更改吗?
发布于 2013-04-07 13:12:26
img = new UnmanagedImage(..., img.Stride, PixelFormat.Format8bppIndexed);这就是问题开始的原因。您正在传递像素数据和24 8bpp图像的步幅,但却撒谎说这是8bpp图像。结果仍然是一个24 and图像和一个彻底混乱的过滤器。
这是行不通的,从24bpp到8bpp的转换要复杂得多。8bpp图像不仅有不同的像素格式和步幅,它还需要一个颜色表(又名调色板)。创建一个好的颜色表的256种颜色,产生一个合理匹配的8bpp图像是困难的。
您需要AForge.Imaging.ColorReduction命名空间中的一个类来完成这项工作。
https://stackoverflow.com/questions/15859642
复制相似问题