tags:

views:

52

answers:

1

I have a sequence of bits for a monochrome image (0 => black, 1 => white). I want to take this data and draw an image on the iPhone in color. If a pixel value == 0, then paint it color1, else color2.

I have gotten absolutely nowhere. Originally, I thought I could use glBitmap, but it is not supported on the iPhone.

Does anyone have an idea of how to do this?

Thanks in advance.

+1  A: 

I highly doubt that this is "the" way of doing it, or even a good way of doing it, but since there are no other responses, here is a possible way:

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();

Also note, that I have not actually tested this on the iPhone, only on the iPad.

kasperjj
@kasperjj - Thanks, it works like a charm.
No One in Particular