Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3322444
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T23:10:57+00:00 2026-05-17T23:10:57+00:00

I am a bit confused. I have an ARGB bitmap into an unsigned char*

  • 0

I am a bit confused. I have an ARGB bitmap into an unsigned char* 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?

To get the array I am using this methods.

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;
}

To test all, I am using this.

- (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];
}

Thanks for read.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-17T23:10:58+00:00Added an answer on May 17, 2026 at 11:10 pm

    You mean, just:

    typedef struct argb_s {
     unsigned char a;
     unsigned char r;
     unsigned char g;
     unsigned char b;
    } argb_t;
    
    argb_t argb = (argb_t *) bitmapData;
    for (i=0;i<size.width * size.height;i++) {
      if ((!argb[i].r) && (!argb[i].g) && (!argb[i].b)) 
        NSLog(@"%d,%d is black",(i%size.width),(i/size.height));
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am bit confused about ADO.Net Data Services. Is it just meant for creating
Bit confused here, I have an on-demand instance but do I get charged even
I am a bit confused with this: I have a page with a set
I'm a bit confused, I have worked with Linq To SQL and gather we
I am a bit confused. I have created a simple form with a one
We have started using MVC framework and now we are bit confused where to
I'm a bit confused on this. I have a data table structured like this:
I am a bit confused and need your help. I have a database that
I'm a bit confused by the documentation here. I have a transaction, which start
I'm a bit confused: I have a function, that takes an Object as argument.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.