cocoaTouch/MapConfigViewController.m
changeset 3366 f0e5ff24fb72
parent 3365 37ac593e9027
child 3369 c7289e42f0ee
equal deleted inserted replaced
3365:37ac593e9027 3366:f0e5ff24fb72
   105     CGContextRef context = UIGraphicsGetCurrentContext();       
   105     CGContextRef context = UIGraphicsGetCurrentContext();       
   106     UIGraphicsPushContext(context);  
   106     UIGraphicsPushContext(context);  
   107     for (int x = 0; x < 32*128; x++) {
   107     for (int x = 0; x < 32*128; x++) {
   108         unsigned char byte = map[x];
   108         unsigned char byte = map[x];
   109         for (int z = 0; z < 8; z++) {
   109         for (int z = 0; z < 8; z++) {
   110             // select the color
   110             // select the color based on the rightmost bit
   111             if ((byte & 0x00000001) != 0)
   111             if ((byte & 0x00000001) != 0)
   112                 CGContextSetRGBFillColor(context, 0.5, 0.5, 0.7, 1.0);
   112                 CGContextSetRGBFillColor(context, 0.5, 0.5, 0.7, 1.0);
   113             else
   113             else
   114                 CGContextSetRGBFillColor(context, 0.0, 0.0, 0.0, 0.0);
   114                 CGContextSetRGBFillColor(context, 0.0, 0.0, 0.0, 0.0);
   115             
   115             
   124         }
   124         }
   125     }
   125     }
   126     UIGraphicsPopContext();
   126     UIGraphicsPopContext();
   127     UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
   127     UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
   128     UIGraphicsEndImageContext();
   128     UIGraphicsEndImageContext();
   129 
   129     
       
   130     // set the image in the button
       
   131     [self.previewButton setImage:image forState:UIControlStateNormal];
       
   132     
   130     /*
   133     /*
       
   134     // http://developer.apple.com/mac/library/qa/qa2001/qa1037.html
   131     CGColorSpaceRef colorspace = CGColorSpaceCreateDeviceGray();
   135     CGColorSpaceRef colorspace = CGColorSpaceCreateDeviceGray();
   132     CGContextRef bitmapImage = CGBitmapContextCreate(mapExp, 128, 32, 8, 128, colorspace, kCGImageAlphaNone);
   136     CGContextRef bitmapImage = CGBitmapContextCreate(mapExp, 128, 32, 8, 128, colorspace, kCGImageAlphaNone);
   133     CGColorSpaceRelease(colorspace);
   137     CGColorSpaceRelease(colorspace);
   134     
   138     
   135     CGImageRef previewCGImage = CGBitmapContextCreateImage(bitmapImage);
   139     CGImageRef previewCGImage = CGBitmapContextCreateImage(bitmapImage);
   136     UIImage *previewImage = [[UIImage alloc] initWithCGImage:previewCGImage];
   140     UIImage *previewImage = [[UIImage alloc] initWithCGImage:previewCGImage];
   137     CGImageRelease(previewCGImage);
   141     CGImageRelease(previewCGImage);
   138     */
   142     */
   139     
       
   140     // set the image in the button
       
   141     [self.previewButton setImage:image forState:UIControlStateNormal];
       
   142 }
   143 }
   143 
   144 
   144 #pragma mark -
   145 #pragma mark -
   145 #pragma mark view management
   146 #pragma mark view management
   146 -(void) viewDidLoad {
   147 -(void) viewDidLoad {