Thursday, 11 March 2010

drawing part of an image into a CGContext


hi all

need advice. using function below determine if area in uiview touched contains part of image or not. idea create context 6 x 6 , point touched in middle of this. using loop determine if of alpha values in 36 pixels greater 0.00.

had working 1 pixel, fine line hard touch part of line ( hence allowing larger area test ).

if function returns true, uiview allowed dragged. code below, if uiview empty of alpha values 0.00 , above 0.
can see going wrong?

code:
-(bool)enabledrag:(cgpoint)touchpoint{     // point cgpoint test          //create copy of on screen image check alpha     //quartzcore framework must #indluded.     uigraphicsbeginimagecontext(self.bounds.size);     [self.layer renderincontext:uigraphicsgetcurrentcontext()];     uiimage *viewimage = uigraphicsgetimagefromcurrentimagecontext();     uigraphicsendimagecontext();     // end of create copy of onscreen image     // create context draw single pixel          bool colormatch = no;     unsigned char pixel[36];     cgcontextref context = cgbitmapcontextcreate(pixel,                                                   6, 6, 8, 6, null,                                                  kcgimagealphaonly);     uigraphicspushcontext(context);     [viewimage  drawatpoint:cgpointmake(-touchpoint.x+3, -touchpoint.y+3)];     uigraphicspopcontext();     cgcontextrelease(context);          cgfloat alpha ;          (int =0; i<36; i++) {         alpha = (pixel[i]/255.0);         nslog(@"alpha  %f",alpha);         if (alpha > 0.00) {             colormatch = yes;         }     }      nslog(@"end of loop");     return colormatch; //return result }
 



Forums iPhone, iPad, and iPod Touch iOS Programming


  • iPhone
  • Mac OS & System Software
  • iPad
  • Apple Watch
  • Notebooks
  • iTunes
  • Apple ID
  • iCloud
  • Desktop Computers
  • Apple Music
  • Professional Applications
  • iPod
  • iWork
  • Apple TV
  • iLife
  • Wireless

No comments:

Post a Comment