Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/333.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 像素格式转换故障_C#_.net_Image Processing_Aforge_Pixelformat - Fatal编程技术网

C# 像素格式转换故障

C# 像素格式转换故障,c#,.net,image-processing,aforge,pixelformat,C#,.net,Image Processing,Aforge,Pixelformat,这是我的代码: 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 BayerDithe

这是我的代码:

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);
这就是结果:

为什么结果不完整?在“主块”中我必须更改的内容是什么

这就是问题的起因。您正在传递像素数据和24bpp图像的步幅,但撒谎说这是8bpp图像。结果仍然是一个24bpp的图像和一个完全混乱的过滤器

这是行不通的,从24bpp到8bpp的转换要复杂得多。8bpp图像不仅具有不同的像素格式和步幅,还需要颜色表(也称调色板)。创建一个具有256种颜色的良好颜色表以生成合理匹配的8bpp图像是很困难的


您需要AForge.Imaging.ColorReduce命名空间中的一个类来完成这项工作。

我怀疑这段代码是否会生成您给出的屏幕截图。您正在分别使用
img
\u img
。抱歉,这是我的失误您将其锁定在24bpp,而您的筛选器将其应用在8bpp。。你认为结果会怎样?我不能改变“主块”之外的任何东西/
img = new UnmanagedImage(..., img.Stride, PixelFormat.Format8bppIndexed);