ios - CGContext Errors only in simulator? -
while testing app bugs noticed in simulator when call 1 of functions set image uiimageview, bunch of cgcontext errors thrown , image never gets set. on devices (i have tested on iphone 5, iphone 3gs , ipad 3), none of these cgcontext errors come , image gets set fine.
anyway looked cgcontext code make happen , following methods involve cgcontext:
- (void)setcroprect:(cgrect)croprect { if(!cgrectequaltorect(_croprect,croprect)){ _croprect = croprect; uigraphicsbeginimagecontextwithoptions(self.bounds.size, no, 0.f); cgcontextref context = uigraphicsgetcurrentcontext(); [[uicolor blackcolor] setfill]; uirectfill(self.bounds); cgcontextsetstrokecolorwithcolor(context, [[uicolor whitecolor] colorwithalphacomponent:0.5].cgcolor); cgcontextstrokerect(context, _croprect); [[uicolor clearcolor] setfill]; uirectfill(cgrectinset(_croprect, 1, 1)); self.imageview.image = uigraphicsgetimagefromcurrentimagecontext(); uigraphicsendimagecontext(); } } - (cgimageref)newscaledimage:(cgimageref)source withorientation:(uiimageorientation)orientation tosize:(cgsize)size withquality:(cginterpolationquality)quality { cgsize srcsize = size; cgfloat rotation = 0.0; switch(orientation) { case uiimageorientationup: { rotation = 0; } break; case uiimageorientationdown: { rotation = m_pi; } break; case uiimageorientationleft:{ rotation = m_pi_2; srcsize = cgsizemake(size.height, size.width); } break; case uiimageorientationright: { rotation = -m_pi_2; srcsize = cgsizemake(size.height, size.width); } break; default: break; } cgcontextref context = cgbitmapcontextcreate(null, size.width, size.height, 8, //cgimagegetbitspercomponent(source), 0, cgimagegetcolorspace(source), kcgimagealphanoneskipfirst//cgimagegetbitmapinfo(source) ); cgcontextsetinterpolationquality(context, quality); cgcontexttranslatectm(context, size.width/2, size.height/2); cgcontextrotatectm(context,rotation); cgcontextdrawimage(context, cgrectmake(-srcsize.width/2 , -srcsize.height/2, srcsize.width, srcsize.height), source); cgimageref resultref = cgbitmapcontextcreateimage(context); cgcontextrelease(context); return resultref; } - (cgimageref)newtransformedimage:(cgaffinetransform)transform sourceimage:(cgimageref)sourceimage sourcesize:(cgsize)sourcesize sourceorientation:(uiimageorientation)sourceorientation outputwidth:(cgfloat)outputwidth cropsize:(cgsize)cropsize imageviewsize:(cgsize)imageviewsize { cgimageref source = [self newscaledimage:sourceimage withorientation:sourceorientation tosize:sourcesize withquality:kcginterpolationnone]; cgfloat aspect = cropsize.height/cropsize.width; cgsize outputsize = cgsizemake(outputwidth, outputwidth*aspect); cgcontextref context = cgbitmapcontextcreate(null, outputsize.width, outputsize.height, cgimagegetbitspercomponent(source), 0, cgimagegetcolorspace(source), cgimagegetbitmapinfo(source)); cgcontextsetfillcolorwithcolor(context, [[uicolor clearcolor] cgcolor]); cgcontextfillrect(context, cgrectmake(0, 0, outputsize.width, outputsize.height)); cgaffinetransform uicoords = cgaffinetransformmakescale(outputsize.width/cropsize.width, outputsize.height/cropsize.height); uicoords = cgaffinetransformtranslate(uicoords, cropsize.width/2.0, cropsize.height/2.0); uicoords = cgaffinetransformscale(uicoords, 1.0, -1.0); cgcontextconcatctm(context, uicoords); cgcontextconcatctm(context, transform); cgcontextscalectm(context, 1.0, -1.0); cgcontextdrawimage(context, cgrectmake(-imageviewsize.width/2.0, -imageviewsize.height/2.0, imageviewsize.width, imageviewsize.height) ,source); cgimageref resultref = cgbitmapcontextcreateimage(context); cgcontextrelease(context); cgimagerelease(source); return resultref; } these cgcontext errors:
jul 31 23:37:37 app[10190] <error>: cgbitmapcontextcreate: unsupported parameter combination: 8 integer bits/component; 16 bits/pixel; 1-component color space; kcgimagealphanoneskipfirst; 1504 bytes/row. jul 31 23:37:37 app[10190] <error>: cgcontextsetinterpolationquality: invalid context 0x0 jul 31 23:37:37 app[10190] <error>: cgcontexttranslatectm: invalid context 0x0 jul 31 23:37:37 app[10190] <error>: cgcontextrotatectm: invalid context 0x0 jul 31 23:37:37 app[10190] <error>: cgcontextdrawimage: invalid context 0x0 jul 31 23:37:37 app[10190] <error>: cgbitmapcontextcreateimage: invalid context 0x0 jul 31 23:37:37 app[10190] <error>: cgbitmapcontextcreate: unsupported parameter combination: 0 integer bits/component; 0 bits/pixel; 0-component color space; kcgimagealphanone; 0 bytes/row. jul 31 23:37:37 app[10190] <error>: cgcontextsetfillcolorwithcolor: invalid context 0x0 jul 31 23:37:37 app[10190] <error>: cgcontextfillrects: invalid context 0x0 jul 31 23:37:37 app[10190] <error>: cgcontextconcatctm: invalid context 0x0 jul 31 23:37:37 app[10190] <error>: cgcontextconcatctm: invalid context 0x0 jul 31 23:37:37 app[10190] <error>: cgcontextscalectm: invalid context 0x0 jul 31 23:37:37 app[10190] <error>: cgcontextdrawimage: invalid context 0x0 jul 31 23:37:37 app[10190] <error>: cgbitmapcontextcreateimage: invalid context 0x0 those methods in app use cgcontexts. said, occurs in simulator , not on devices have tested on.
anyway, there particular reason or there way can fix this?
thanks all!
cgcontextref context = cgbitmapcontextcreate(null, size.width, size.height, cgimagegetbitspercomponent(source), //8, 0, cgimagegetcolorspace(source), cgimagegetbitmapinfo //kcgimagealphanoneskipfirst(source) );
most likely, first call cgbitmapcontextcreate failing, because asking cannot do. can see in first error message:
cgbitmapcontextcreate: unsupported parameter combination: 8 integer bits/component; 16 bits/pixel; 1-component color space; kcgimagealphanoneskipfirst; 1504 bytes/row. cgbitmapcontextcreate returns null, , rest of failures cascade there. (you cannot operate on null context, , calling cgbitmapcontextgetimage() on null context gives null image, can't useful with.)
the documentation cgbitmapcontextcreate states:
for list of supported pixel formats, see “supported pixel formats” in “graphics contexts” chapter of quartz 2d programming guide.
here's direct link list.
Comments
Post a Comment