ios - Get color from pixel in Objective-C -


i want color coordination on screen , place in variable. i'm using theos , i'm messing around on ios 5 device learning please don't start "stop wasting time making tweaks old ios" i've seen on posts :|

try below code:

// uiview+colorofpoint.h @interface uiview (colorofpoint) - (uicolor *) colorofpoint:(cgpoint)point; @end  // uiview+colorofpoint.m #import "uiview+colorofpoint.h" #import <quartzcore/quartzcore.h>  @implementation uiview (colorofpoint)  - (uicolor *) colorofpoint:(cgpoint)point {     unsigned char pixel[4] = {0};      cgcolorspaceref colorspace = cgcolorspacecreatedevicergb();      cgcontextref context = cgbitmapcontextcreate(pixel, 1, 1, 8, 4, colorspace, kcgbitmapalphainfomask & kcgimagealphapremultipliedlast);      cgcontexttranslatectm(context, -point.x, -point.y);      [self.layer renderincontext:context];      cgcontextrelease(context);     cgcolorspacerelease(colorspace);      //nslog(@"pixel: %d %d %d %d", pixel[0], pixel[1], pixel[2], pixel[3]);      uicolor *color = [uicolor colorwithred:pixel[0]/255.0 green:pixel[1]/255.0 blue:pixel[2]/255.0 alpha:pixel[3]/255.0];      return color; } 

you can find files here: https://github.com/ivanzoid/ikit/tree/master/uiview%2bcolorofpoint

also, check answers here more info: how color of pixel in uiview?


Comments

Popular posts from this blog

Is there a better way to structure post methods in Class Based Views -

performance - Why is XCHG reg, reg a 3 micro-op instruction on modern Intel architectures? -

jquery - Responsive Navbar with Sub Navbar -