Note that there are some explanatory texts on larger screens.

plurals
  1. POHow Can I Iterate an ARGB Bitmap?
    primarykey
    data
    text
    <p>I am a bit confused. I have an ARGB bitmap into an <code>unsigned char*</code> array and I just want to iterate the array to check if pixels are black or white. Can anyone post me a sample code for this?</p> <p>To get the array I am using this methods.</p> <pre><code>CGContextRef CreateARGBBitmapContext (CGSize size) { CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB(); if (colorSpace == NULL) { fprintf(stderr, "Error allocating color space\n"); return NULL; } void *bitmapData = malloc(size.width * size.height * 4); if (bitmapData == NULL) { fprintf (stderr, "Error: Memory not allocated!"); CGColorSpaceRelease(colorSpace); return NULL; } CGContextRef context = CGBitmapContextCreate (bitmapData, size.width, size.height, 8, size.width * 4, colorSpace, kCGImageAlphaPremultipliedFirst); CGColorSpaceRelease(colorSpace ); if (context == NULL) { fprintf (stderr, "Error: Context not created!"); free (bitmapData); return NULL; } return context; } - (unsigned char *)bitmapFromImage:(UIImage *)image { //Create a bitmap for the given image. CGContextRef contex = CreateARGBBitmapContext(image.size); if (contex == NULL) { return NULL; } CGRect rect = CGRectMake(0.0f, 0.0f, image.size.width, image.size.height); CGContextDrawImage(contex, rect, image.CGImage); unsigned char *data = CGBitmapContextGetData(contex); CGContextRelease(contex); return data; } </code></pre> <p>To test all, I am using this.</p> <pre><code>- (void)viewDidLoad { [super viewDidLoad]; NSString *path = [[NSBundle mainBundle] pathForResource:@"verticalLine320x460" ofType:@"png"]; UIImage *image = [[UIImage alloc] initWithContentsOfFile:path]; unsigned char *imageBitmap = (unsigned char *)[self bitmapFromImage:image]; [image release]; } </code></pre> <p>Thanks for read.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload