我想创建一个黑白图像,所以它是 1bpp。现在这是我的代码,它根据阈值将图像转换为黑白:
- (UIImage *)pureBlackAndWhiteImage:(UIImage *)image value:(float)value {
unsigned char *dataBitmap = [self convertUIImageToBitmapRGBA8:image];
for (int i = 0; i < image.size.width * image.size.height * 4; i += 4) {
if ((dataBitmap[i + 0] + dataBitmap[i + 1] + dataBitmap[i + 2]) < value) {
dataBitmap[i + 0] = 0;
dataBitmap[i + 1] = 0;
dataBitmap[i + 2] = 0;
} else {
dataBitmap[i + 0] = 255;
dataBitmap[i + 1] = 255;
dataBitmap[i + 2] = 255;
}
}
image = [self convertBitmapRGBA8ToUIImage:dataBitmap withWidth:image.size.width withHeight:image.size.height];
return image;
}
然而,这个图像仍然是 8bpp。我怎样才能使它成为1bpp?