如何在iPhone上使用单色位图显示彩色图像?
我有一个单色图像的位序列(0=>黑色,1=>白色)。我想用这些数据在iPhone上画一幅彩色图像。如果像素值==0,则将其绘制为color1,否则绘制为color2 我一事无成。最初,我认为我可以使用glBitmap,但iPhone不支持它 有人知道怎么做吗如何在iPhone上使用单色位图显示彩色图像?,iphone,Iphone,我有一个单色图像的位序列(0=>黑色,1=>白色)。我想用这些数据在iPhone上画一幅彩色图像。如果像素值==0,则将其绘制为color1,否则绘制为color2 我一事无成。最初,我认为我可以使用glBitmap,但iPhone不支持它 有人知道怎么做吗 提前感谢。我非常怀疑这是一种“正确”的方式,甚至是一种好的方式,但由于没有其他回应,这里有一种可能的方式: UIGraphicsBeginImageContext(CGSizeMake(width,height)); CGCon
提前感谢。我非常怀疑这是一种“正确”的方式,甚至是一种好的方式,但由于没有其他回应,这里有一种可能的方式:
UIGraphicsBeginImageContext(CGSizeMake(width,height));
CGContextRef context = UIGraphicsGetCurrentContext();
UIGraphicsPushContext(context);
for(int y=0;y<height,y++){
for(int x=0;x<width;x++){
int val=map[x+y*width];
if(val==0){
CGContextSetRGBFillColor(context, 0.0,0.0,0.0,1.0);
}else{
CGContextSetRGBFillColor(context, 1.0,1.0,1.0,1.0);
}
CGContextFillRect(context,CGRectMake(x,y,1,1));
}
}
UIGraphicsPopContext();
UIImage* image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
UIGraphicsBeginImageContext(CGSizeMake(宽度、高度));
CGContextRef context=UIGraphicsGetCurrentContext();
UIGraphicsPushContext(context);
对于(int y=0;y