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

前端 未结 12 931
清酒与你
清酒与你 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:14

    Draw the bitmap with a ColorMatrix that has 3 x 255 in the diagonal, that will blow any non-black pixel to pure white. Then draw that bitmap to a smaller one whose width is a multiple of 4 and has the Format24bppRgb format. That eliminates the alpha, reduces the size and leaves only zeros if the bitmap is truly black.

    You'll have to experiment to see how small you can make the bitmap, use a sample one that has only one white pixel to see when the interpolator makes it disappear. I'm guessing you can go pretty far.

提交回复
热议问题