Oleg Filimonov Oleg Filimonov - 5 months ago 47
C# Question

Check if image is plain white?

I need to check if the PNG image that has constant size (512x512 pixels) has only white pixels and nothing else or not.

Is there an easy way to do this, preferably without checking every pixel manually? Maybe using ImageMagick?


I don't think there is a magic way of determining whether an image is white.

You'll probably just have to check all pixels, but you can have fast access to your image if you convert it to bitmap and, instead of using GetPixel(), you lock the bitmap in memory using the LockBits() method. Then you can work with the BitmapData type and write your own, fast, GetPixel(), as explained here: Working with BitmapData.


Actually, I though of another way: you can create a plain white image of the same size, and then compare your image to that one by computing and comparing their hashes. Take a look at this: Comparing two images.