objective c - CoreGraphics drawAtPoint with invalid context -


i bit new core graphics , keep error , second image not showing when merge them:

- (uiimage*)imagebycombiningimage:(uiimage*)gfirstimage withimage:(uiimage*)gsecondimage atpositionx:(int)xposition withpositiony:(int)yposition{      uiimage *firstimage = nil;     uiimage *secondimage = nil;      firstimage = gfirstimage;     secondimage = gsecondimage;      // int ratio = secondimage.size.height/secondimage.size.width;     // int newwidth = firstimage.size.width/3;     // int newheight = (firstimage.size.height/3)*ratio;     cgsize scaledsize = cgsizemake(firstimage.size.width, firstimage.size.height);     cgsize badgescaledsize = scaledsize;     if(firstimage.size.width > 500){         scaledsize = cgsizemake(firstimage.size.width/4, firstimage.size.height/3);     }      if(firstimage.size.width < firstimage.size.height){         badgescaledsize = cgsizemake((firstimage.size.width/4)*prevpinchscale, (firstimage.size.height/4)*prevpinchscale);     }      if(firstimage.size.width > firstimage.size.height){         badgescaledsize = cgsizemake((firstimage.size.width/4)*prevpinchscale, (firstimage.size.height/4)*prevpinchscale);     }        secondimage = [secondimage resizedimagewithcontentmode:uiviewcontentmodescaleaspectfit bounds:badgescaledsize interpolationquality:0.5];      cgsize newimagesize = cgsizemake(firstimage.size.width, firstimage.size.height);      uigraphicsbeginimagecontext(newimagesize);      nslog(@"first image size width: %f, size height: %f", firstimage.size.width, firstimage.size.height);     nslog(@"first image size width: %f, size height: %f", newimagesize.width, newimagesize.height);      [firstimage drawatpoint:cgpointmake(0,                                         0)];       [secondimage drawatpoint:cgpointmake(xposition,                                          yposition)];      uiimage *image = nil;     image = uigraphicsgetimagefromcurrentimagecontext();      nslog(@"got image of width: %f , height: %f", image.size.width, image.size.height);      uigraphicsendimagecontext();       return image; } 

the error follows:

 <error>: cgcontextconcatctm: invalid context 0x0  <error>: cgcontextsetinterpolationquality: invalid context 0x0  <error>: cgcontextdrawimage: invalid context 0x0  <error>: cgbitmapcontextcreateimage: invalid context 0x0 

those errors not being thrown code, rather inside uiimage+resize.m assuming using. code runs fine if remove line

secondimage = [secondimage resizedimagewithcontentmode:uiviewcontentmodescaleaspectfit bounds:badgescaledsize interpolationquality:0.5]; 

if @ method find calls method makes 4 calls getting errors from.

- (uiimage *)resizedimage:(cgsize)newsize             transform:(cgaffinetransform)transform        drawtransposed:(bool)transpose  interpolationquality:(cginterpolationquality)quality { cgrect newrect = cgrectintegral(cgrectmake(0, 0, newsize.width, newsize.height)); cgrect transposedrect = cgrectmake(0, 0, newrect.size.height, newrect.size.width); cgimageref imageref = self.cgimage;  // build context that's same dimensions new size cgcontextref bitmap = cgbitmapcontextcreate(null,                                             newrect.size.width,                                             newrect.size.height,                                             cgimagegetbitspercomponent(imageref),                                             0,                                             cgimagegetcolorspace(imageref),                                             cgimagegetbitmapinfo(imageref));  // rotate and/or flip image if required orientation cgcontextconcatctm(bitmap, transform);  // set quality level use when rescaling cgcontextsetinterpolationquality(bitmap, quality);  // draw context; scales image cgcontextdrawimage(bitmap, transpose ? transposedrect : newrect, imageref);  // resized image context , uiimage cgimageref newimageref = cgbitmapcontextcreateimage(bitmap); uiimage *newimage = [uiimage imagewithcgimage:newimageref];  // clean cgcontextrelease(bitmap); cgimagerelease(newimageref);  return newimage; } 

it seems value bitmap invalid. check make sure on cgbitmapcontextcreate call, passing real values , not creating context of size 0x0.


Comments