Getting a Black and White UIImage (Not Grayscale)

前端 未结 6 1700
独厮守ぢ
独厮守ぢ 2021-02-04 20:23

I need to get a pure black and white UIImage from another UIImage (not grayscale). Anyone can help me?

Thanks for reading.

EDITED:

Here

6条回答
  •  无人共我
    2021-02-04 20:51

    This code may help:

    for (int i = 0; i < image.size.width * image.size.height * 4; i += 4) {
            if (dataBitmap[i + 0] >= dataBitmap[i + 1] && dataBitmap[i + 0] >= dataBitmap[i + 2]){
            dataBitmap[i + 1] = dataBitmap[i + 0];
            dataBitmap[i + 2] = dataBitmap[i + 0];
        }
        else if (dataBitmap[i + 1] >= dataBitmap[i + 0] && dataBitmap[i + 1] >= dataBitmap[i + 2]) {
            dataBitmap[i + 0] = dataBitmap[i + 1];
            dataBitmap[i + 2] = dataBitmap[i + 1];
        }
        else  {
            dataBitmap[i + 0] = dataBitmap[i + 2];
            dataBitmap[i + 1] = dataBitmap[i + 2];
        }
    }
    

提交回复
热议问题