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 7791607
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T21:56:19+00:00 2026-06-01T21:56:19+00:00

I’ve two images of the same format and size. I would like to loop

  • 0

I’ve two images of the same format and size.

I would like to loop over the pixels of each image and find the most top left and buttom right difference coordinates.

Difference is considered the pixel color of the two pixel with the same coordinates.

Can you please provide me a sample code looping through Image pixels and getting its color value ?

  • 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-06-01T21:56:20+00:00Added an answer on June 1, 2026 at 9:56 pm

    This works for me (this is using ARC):

    - (BOOL) pointInside: (CGPoint) point withEvent: (UIEvent *) event {
        CGRect r = CGRectZero ;
    
        r.size =[self size] ;
    
        CGFloat red ;
        CGFloat green ;
        CGFloat blue ;
        CGFloat alpha ;
    
        if (point.x < 0 || point.x > r.size.width || point.y < 0 || point.y > r.size.height) {
            return NO ;
        }
    
        [inspector colorAt:point red:&red green:&green blue:&blue alpha:&alpha] ;
    
        return alpha > 0.01f ;
    }
    

    And here’s the magic 🙂

    // CGImageInspection.h
    #import <Foundation/Foundation.h>
    
    @interface CGImageInspection : NSObject
    
    + (CGImageInspection *) imageInspectionWithCGImage: (CGImageRef) imageRef ;
    
    - (void) colorAt: (CGPoint) location
                 red: (CGFloat *) red 
               green: (CGFloat *) green
                blue: (CGFloat *) blue
               alpha: (CGFloat *) alpha ;
    
    @end
    

    And the corresponding implementation:

    // CGImageInspection.mm
    @interface CGImageInspection ()
    
    - (id) initWithCGImage: (CGImageRef) imageRef ;
    
    @property (assign, nonatomic) CGContextRef  context ;
    @property (assign, nonatomic) void *        pixels ;
    @property (assign, nonatomic) NSUInteger    bytesPerRow ;
    @property (assign, nonatomic) NSUInteger    bytesPerPixel ;
    
    @end
    
    @implementation CGImageInspection
    
    @synthesize context ;
    @synthesize pixels ;
    @synthesize bytesPerRow ;
    @synthesize bytesPerPixel ;
    
    - (void) dealloc {
        if (self.context) {
            ::CGContextRelease(self.context) ;
            self.context = 0 ;
        }
    
        if (self.pixels) {
            ::free(self.pixels) ;
            self.pixels = 0 ;
        }
    
        ::NSLog(@"CGImageInspection going away") ;
    }
    
    + (CGImageInspection *) imageInspectionWithCGImage: (CGImageRef) imageRef {
        return [[CGImageInspection alloc] initWithCGImage:imageRef] ;
    }
    
    - (id) initWithCGImage: (CGImageRef) imageRef {
    
        if (self = [super init]) {
            size_t  pixelsWide = ::CGImageGetWidth(imageRef) ;
            size_t  pixelsHigh = ::CGImageGetHeight(imageRef) ;
    
            self.bytesPerPixel = 4 ;
            self.bytesPerRow = (pixelsWide * self.bytesPerPixel) ;
            int     bitmapByteCount   = (self.bytesPerRow * pixelsHigh) ;
    
            CGColorSpaceRef colorSpace= ::CGColorSpaceCreateDeviceRGB() ;
    
            if (colorSpace == 0) {
                return nil ;
            }
    
            self.pixels = ::calloc(bitmapByteCount, 1) ;
            if (self.pixels == 0) {
                ::CGColorSpaceRelease(colorSpace) ;
                return nil ;
            }
    
            self.context = ::CGBitmapContextCreate(
                self.pixels
            ,   pixelsWide
            ,   pixelsHigh
            ,   8      // bits per component
            ,   self.bytesPerRow
            ,   colorSpace
            ,   kCGImageAlphaPremultipliedLast | kCGBitmapByteOrder32Big) ;
    
            if (self.context == 0) {
                ::free(self.pixels) ;
                self.pixels = 0 ;
                ::CGColorSpaceRelease(colorSpace) ;
                return nil ;
            }
            ::CGContextDrawImage(context, (CGRect) {{0, 0}, {pixelsWide, pixelsHigh}}, imageRef) ;
            ::CGColorSpaceRelease(colorSpace) ;
        }
    
        return self ;
    
    }
    
    - (void) colorAt: (CGPoint) location
                 red: (CGFloat *) red 
               green: (CGFloat *) green
                blue: (CGFloat *) blue
               alpha: (CGFloat *) alpha {
    
        int yy = (int) location.y ;
        int xx = (int) location.x ;
    
        int byteIndex = (bytesPerRow * yy) + xx * bytesPerPixel ;
        unsigned char * raw = (unsigned char *) self.pixels ;
        raw += byteIndex ;
    
        *red    = ((CGFloat) (*raw++)) / 255.0f ;
        *green  = ((CGFloat) (*raw++)) / 255.0f ;
        *blue   = ((CGFloat) (*raw++)) / 255.0f ;
        *alpha  = ((CGFloat) (*raw++)) / 255.0f ;
    }
    
    @end
    

    Hope this helps.

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

Sidebar

Related Questions

I would like to count the length of a string with PHP. The string
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I would like to run a str_replace or preg_replace which looks for certain words
Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text
I've got a string that has curly quotes in it. I'd like to replace
I am trying to render a haml file in a javascript response like so:
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
Seemingly simple, but I cannot find anything relevant on the web. What is the

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.