this is my code:

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);

This is result: screenshot

Why result is not complited Oo? And what i must change only in "MAIN BLOCK"?

有帮助吗?

解决方案

img = new UnmanagedImage(..., img.Stride, PixelFormat.Format8bppIndexed);

That's the statement where the problem started. You are passing the pixel data and the stride of a 24bpp image but lied and said it is an 8bpp image. The result is still a 24bpp image and a thoroughly confused filter.

This cannot work, conversion from 24bpp to 8bpp is far more involved. The 8bpp image won't only have a different pixel format and stride, it also requires a color table (aka palette). Creating a good color table with 256 colors that produces a reasonably matching 8bpp image is difficult.

You'll need one of the classes in the AForge.Imaging.ColorReduction namespace to get that job done.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top