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

  • Home
  • SEARCH
  • 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 7091699
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T08:13:08+00:00 2026-05-28T08:13:08+00:00

I have an image! It’s been so long since I’ve done pixel detection, I

  • 0

I have an image! It’s been so long since I’ve done pixel detection, I remember you have to convert the pixels to an array somehow and then find the width of the image to find out when the pixels reach the end of a row and go to the next one and ahh, lots of complex stuff haha! Anyways I now have no clue how to do this anymore but I need to detect the left-most darkest pixel’s x&y coordinates of my image named “image1″… Any good starting places?

  • 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-28T08:13:09+00:00Added an answer on May 28, 2026 at 8:13 am

    Go to your bookstore, find a book called “iOS Developer’s Cookbook” by Erica Sadun. Go to page 378-ish and there are methods for pixel detection there. You can look in this array of RGB values and run a for loop to sort and find the pixel that has the smallest sum of R, G, and B values (this will be 0-255) that will give you the pixel closest to black.
    I can also post the code if needed. But the book is the best source as it gives methods and explanations.

    These are mine with some changes. The method name remains the same. All I changed was the image which basically comes from an image picker.

    -(UInt8 *) createBitmap{
    if (!self.imageCaptured) {
            NSLog(@"Error: There has not been an image captured.");
            return nil;
        }
        //create bitmap for the image
        UIImage *myImage = self.imageCaptured;//image name for test pic
        CGContextRef context = CreateARGBBitmapContext(myImage.size);
        if(context == NULL) return NULL;
        CGRect rect = CGRectMake(0.0f/*start width*/, 0.0f/*start*/, myImage.size.width /*width bound*/, myImage.size.height /*height bound*/); //original
    //    CGRect rect = CGRectMake(myImage.size.width/2.0 - 25.0 /*start width*/, myImage.size.height/2.0 - 25.0 /*start*/, myImage.size.width/2.0 + 24.0 /*width bound*/, myImage.size.height/2.0 + 24.0 /*height bound*/); //test rectangle
    
        CGContextDrawImage(context, rect, myImage.CGImage);
        UInt8 *data = CGBitmapContextGetData(context);
        CGContextRelease(context);    
        return data;
    }
    CGContextRef CreateARGBBitmapContext (CGSize size){
    
        //Create new color space
        CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
        if (colorSpace == NULL) {
            fprintf(stderr, "Error allocating color space\n");
            return NULL;
        }
        //Allocate memory for bitmap data
        void *bitmapData = malloc(size.width*size.height*4);
        if(bitmapData == NULL){
            fprintf(stderr, "Error: memory not allocated\n");
            CGColorSpaceRelease(colorSpace);
            return NULL;
        }
        //Build an 8-bit per channel context
        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;
    
    }
    NSUInteger blueOffset(NSUInteger x, NSUInteger y, NSUInteger w){
        return y*w*4 + (x*4+3);
    }
    NSUInteger redOffset(NSUInteger x, NSUInteger y, NSUInteger w){
        return y*w*4 + (x*4+1);
    }
    

    The method on the bottom, redOffset, will get you the Red value in the ARGB (Alpha-Red-Green-Blue) scale. To change what channel in the ARGB you are looking at, change the value added to the x variable in the redOffset function to 0 to find alpha, keep it at 1 to find red, 2 to find green, and 3 to find blue. This works because it just looks at an array made in the methods above and the addition to x accounts for the index value. Essentially, use methods for the three colors (Red, green, and blue) and find the summation of those for each pixel. Whichever pixel has the lowest value of red, green, and blue together is the most black.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have image size 32*32 and have array of each pixel color.This color is
I have something like that - image loaded from file to picturebox1: then after
I have managed objects that have image properties. Since storing large blobs in CoreData
I have image data and i want to get a sub image of that
I have: image 1:Many imageToTag Many:1 tag I want to issue a query that
I have image and txt file of same size say 200 KB. Now i
So I have Image like this (source: de-viz.ru ) I want to get something
So I have Image like this (source: de-viz.ru ) I want to get something
I have a problem... In my view i have Image.If i click on image
I my working on the site that will have image gallery. Designer idea was

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.