objective c - iOS using UIGraphicsGetImageFromCurrentImageContext to detect certain pixels on screen -


i have uiview user can draw various uibezierpaths.

i need analyze drawn bezierpaths process patterns. have not found solution converting uibezierpaths list of coordinates/points, seems undoable? it's strange data must stored , used someway draw actual paths..

so bypass problem decided draw bezierpath width of 1px:

[path setlinewidth:1]; 

and convert uiview uiimage:

uigraphicsbeginimagecontextwithoptions(self.bounds.size, no, 0.0); [self.layer renderincontext:uigraphicsgetcurrentcontext()]; uiimage *viewimage = uigraphicsgetimagefromcurrentimagecontext(); 

then can identify pixels getting color pixel position @ image:

- (uicolor *)coloratpixel:(cgpoint)point {     cgimageref imageref = [self cgimage];     nsuinteger width = cgimagegetwidth(imageref);     nsuinteger height = cgimagegetheight(imageref);     cgcolorspaceref colorspace = cgcolorspacecreatedevicergb();     int bytesperpixel = 4;     long bytesperrow = bytesperpixel * width;     int bitspercomponent = 8;      unsigned char *rawdata = (unsigned char*) calloc(height * width * 4, sizeof(unsigned char));      cgcontextref context = cgbitmapcontextcreate(rawdata,                                                  width,                                                  height,                                                  bitspercomponent,                                                  bytesperrow,                                                  colorspace,                                                  kcgimagealphapremultipliedlast | kcgbitmapbyteorder32big);      cgcolorspacerelease(colorspace);     cgcontextdrawimage(context, cgrectmake(0, 0, width, height), imageref);     cgcontextrelease(context);      // rawdata contains image data in rgba8888 pixel format.     long byteindex = (bytesperrow * point.y) + point.x * bytesperpixel;     cgfloat red   = (rawdata[byteindex] * 1.0) / 255.0;     cgfloat green = (rawdata[byteindex + 1] * 1.0) / 255.0 ;     cgfloat blue  = (rawdata[byteindex + 2] * 1.0) / 255.0 ;     cgfloat alpha = (rawdata[byteindex + 3] * 1.0) / 255.0;      byteindex += 4;     uicolor *color = [uicolor colorwithred:red green:green blue:blue alpha:alpha];     free(rawdata);      return color; } 

now issue image generated blurry, if draw straight 1px bezierpath line , convert uiimage, line has width of 3x because of becomming blurry.

how can solve this? there no possible way convert bezierpaths list of coordinates?

this due anti alias rendering.

see question on information on how turn of.

i believe better of rendering beziercurve yourself. faster small memory footprint.


Comments