ios - CGContextDrawLayerInRect from CGBitmapContextCreate failing iPhone 7 Plus -


i've got objective c project @ 1 point takes photo either photo library or camera, , chops them little squares (tiles), , creates new uiimage objects chopped squares.

the code works perfectly on older iphone 5 , on ipad mini 2.

on iphone 7 plus, however, produces blank output (instead of chopped parts of input). ipad mini 2 , iphone 7 plus both running ios 10.3.3, , both 64-bit devices.

the complete function here:

-(void) createtilesfromimage:(uiimage*)img inrect:(cgrect)rect incontext:(cgcontextref)context {      if (tilesdefined) {             return;     }      tilesdefined = yes;       // tileboard layer     cgsize tileboardsize = rect.size;     tileboardrect = rect;      // chop image     cglayerref imagetochop = cglayercreatewithcontext(context, tileboardsize, null);     cgcontextref ctx2 = cglayergetcontext(imagetochop);     uigraphicspushcontext(ctx2);     [img drawinrect:cgrectmake(0, 0, tileboardsize.width, tileboardsize.height)];     uigraphicspopcontext();      // tile layer size (cg & ca)     tilesize = cgsizemake(ceilf(tileboardsize.width / dims.x),ceilf( tileboardsize.height / dims.y ));      // bitmap context     cgcontextref bmpcontext = [[qpdrawing shared] newcgbitmapcontextwithsize:tilesize withdata:yes];      // create tile layers     tiles = [[nsmutablearray alloc] initwithcapacity:dims.x * dims.y];     int = 0;     (int y = 0; y < dims.y; y++) {             (int x = 0; x < dims.x; x++) {                     tilelayers[i] = cglayercreatewithcontext(context, tilesize, null);                                     cgcontextref squarecontext = cglayergetcontext(tilelayers[i]);                     cgpoint offset = cgpointmake(x * tileboardsize.width / dims.x * -1, y * tileboardsize.height / dims.y * -1);                      // invert layer prior drawing                     cgcontexttranslatectm(squarecontext, 0, tilesize.height);                     cgcontextscalectm(squarecontext, 1.0, -1.0);                     cgcontextdrawlayeratpoint(squarecontext, offset, imagetochop);                      cgcontextdrawlayerinrect(bmpcontext, (cgrect){0,0,tilesize.width,tilesize.height}, tilelayers[i]);                     cgimageref imageref = cgbitmapcontextcreateimage( bmpcontext );                      [tiles addobject: [uiimage imagewithcgimage: imageref]];                      cgimagerelease(imageref);                      i++;             }     }      // cleanup     cglayerrelease(imagetochop);     cgcontextrelease(bmpcontext);      rect = cgrectinset(rect, 2, 2);     cgcontextaddrect(context, rect);     cgcontextsetstrokecolorwithcolor(context, [uicolor colorwithred:1 green:0 blue:0 alpha:1].cgcolor);     cgcontextsetlinewidth(context, 2);     cgcontextstrokepath(context); } 

this calls 1 outside piece when creating cgcontextref, bmpcontext -- newcgbitmapcontextwithsize:tilesize:withdata. code bit below:

- (cgcontextref) newcgbitmapcontextwithsize:(cgsize)size withdata:(bool)includedata {      cgcolorspaceref colorspace = cgcolorspacecreatedevicergb();     int width = (int)ceilf(size.width);     int height = (int)ceilf(size.height);     size_t bitspercomponent = 8;     size_t bytesperpixel    = 4;     size_t bytesperrow      = (width * bitspercomponent * bytesperpixel + 7) / 8;     size_t datasize         = bytesperrow * height;      unsigned char *data = null;      if (includedata) {             data = malloc(datasize);             memset(data, 0, datasize);     }      cgcontextref context = cgbitmapcontextcreate(data, size.width, size.height,             bitspercomponent, bytesperrow, colorspace,             kcgimagealphapremultipliedlast | kcgbitmapbyteorder32big);      cgcolorspacerelease(colorspace);     return context; } 

at first thought "drawinrect" call somehow wasn't working, i'm convinced isn't case. think it's somehow related cgbitmapcontextcreate call.

thanks!

it seems me you're doing more work need to; perhaps overthinking problem how divide image tiles. might interested in simpler way. in diabelli's theme app. it's swift don't think you'll have trouble reading (i have old objective-c code sitting around if need it).

obviously, loop through "tiles" image divided. have worked out number of rows , colums, , size of tile, w h. original image im. have do:

for row in 0..<rows {     col in 0..<cols {         uigraphicsbeginimagecontextwithoptions(cgsize(             width: cgfloat(w),height: cgfloat(h)), true, 0)         im.draw(at: cgpoint(x: cgfloat(-w*col),y: cgfloat(-h*row)))         let tileimage = uigraphicsgetimagefromcurrentimagecontext()         uigraphicsendimagecontext()         // tileimage     } } 

Comments

Popular posts from this blog

resizing Telegram inline keyboard -

command line - How can a Python program background itself? -

php - "cURL error 28: Resolving timed out" on Wordpress on Azure App Service on Linux -