原創|使用教程|編輯:郝浩|2013-09-26 11:02:34.000|閱讀 330 次
概述:如何判斷一個24/32位圖像是彩色、灰階還是黑白的?您可以使用ImageMan.Net文件的類來判斷。
# 界面/圖表報表/文檔/IDE等千款熱門軟控件火熱銷售中 >>
如何判斷一個24/32位圖像是彩色、灰階還是黑白的?您可以使用ImageMan.Net文件的類來判斷。
下面是一些示例代碼使用:
// Requires a reference to the DTI.ImageMan.TessOcr assembly using DTI.ImageMan; ColorAnalyzer a = new ColorAnalyzer(viewer1.Images.CurrentImage); Console.WriteLine("Color = {0}, Greyscale = {1}, Black&WHite = {2}", a.IsColor, a.IsGreyscale, a.IsBlackAndWhite); if (a.IsGreyscale) Console.WriteLine("{0} Grey Entries", a.GreyScaleEntries);
值得注意:
1.目前只支持4、8、24和32位圖像,不支持16位的圖像,但在不久的將來會支持。
2.大多數情況下掃描圖像是黑白圖像,但也有一些灰階像素圖,在這種情況下,它會返回IsGreyscale==ture,您可以檢查GreyScaleEntries的屬性,看有多少灰階項,如果只是小數目,它可能將值減少到1比特的圖像。你也可以修改此代碼,以確認周圍聚集的黑白作品灰度項。
3.這需要在你的解決方案中引用DTI.ImageMan.TessOcr。
The ColorAnalyzerClass: public class ColorAnalyzer { int[,] histogram; public ColorAnalyzer(ImImage img) { histogram = Analyze.GetColorHistogram(img); GreyScaleEntries = 0; // Check for Color and Greyscale for( int i = 0; i < 256; i++ ) { if (histogram[0, i] == histogram[1, i] && histogram[1, i] == histogram[2, i]) { if (histogram[0, i] > 0) { GreyScaleEntries++; IsGreyscale = true; } } else { IsGreyscale = false; IsColor = true; } } // This could be a black & White image so lets check if (IsGreyscale) { if (GreyScaleEntries == 2 && histogram[0, 0] > 0 && histogram[0, 255] > 0) { IsBlackAndWhite = true; IsGreyscale = false; } } } public bool IsColor; public bool IsGreyscale; public bool IsBlackAndWhite; public int GreyScaleEntries; }
本站文章除注明轉載外,均為本站原創或翻譯。歡迎任何形式的轉載,但請務必注明出處、不得修改原文相關鏈接,如果存在內容上的異議請郵件反饋至chenjj@fc6vip.cn
文章轉載自:慧都控件網