.NET ez 2012-08-23
本篇利用 BitmapData 檢查圖片是否為空白!
※定義:全黑或全白就算是空白。
//檢查圖片是否擷取成功 bool NotNULL = false; using (Bitmap b = (Bitmap)Bitmap.FromFile(ScreenshotRoute)) { BitmapData bData = b.LockBits(new Rectangle(0, 0, b.Width, b.Height), ImageLockMode.ReadWrite, PixelFormat.Format24bppRgb); unsafe { byte* p = (byte*)bData.Scan0.ToPointer(); for (int y = 0; y < b.Height; y++) { for (int x = 0; x < b.Width; x++) { if ((p[0] != 255 && p[0] != 0) || (p[1] != 255 && p[1] != 0) || (p[2] != 255 && p[2] != 0)) { NotNULL = true; break; } p += 3; } if (NotNULL) break; } b.UnlockBits(bData); } } Console.WriteLine(NotNULL ? "不是空白" : "空白");
標籤: .NET
本文章網址:
https://www.ez2o.com/Blog/Post/csharp-Check-Image-Empty-BitmapData
https://www.ez2o.com/Blog/Post/283
https://www.ez2o.com/Blog/Post/csharp-Check-Image-Empty-BitmapData
https://www.ez2o.com/Blog/Post/283