What's an efficient way to tell if a bitmap is entirely black?

前端 未结 12 920
清酒与你
清酒与你 2021-02-05 05:40

I\'m wondering if there\'s a super-efficient way of confirming that an Image object references an entirely black image, so every pixel within the bitmap is ARGB(255, 0, 0, 0).

12条回答
  •  清歌不尽
    2021-02-05 06:22

    I have an idea that's outside the box.

    What about a CRC checksum? You could first check the dimensions of the image, then calculate the checksum and compare that to known (precalculated) checksums of an all-black image of the same dimensions.

    EDIT: I doubt this would be any faster than @leonard's method. The only reason it might is if the original file was not a bitmap, but was a compressed image format. That way, the CRC checksum algorithm wouldn't have to uncompress the image before running.

提交回复
热议问题