iphone privateapi - IOSurface - IOS Private API - Capture screenshot in background -
i want capture screenshot background service. private api fine don't need submit app store. have tried uigetscreenimage , not work background app.
i using following code got so. iosurfacecreate returns null me. appreciated.
cfmutabledictionaryref dict; iosurfaceref screensurface = null; char pixelformat[4] = {'a','r','g','b'}; dict = cfdictionarycreatemutable(kcfallocatordefault, 0, &kcftypedictionarykeycallbacks, &kcftypedictionaryvaluecallbacks); uint32_t width ; uint32_t height; void *pitch; void *bpe; void *size; cfdictionarysetvalue(dict, kiosurfaceisglobal, kcfbooleantrue); cfdictionarysetvalue(dict, kiosurfacebytesperrow, cfnumbercreate(kcfallocatordefault, kcfnumbersint32type, &pitch)); cfdictionarysetvalue(dict, kiosurfacebytesperelement, cfnumbercreate(kcfallocatordefault, kcfnumbersint32type, &bpe)); cfdictionarysetvalue(dict, kiosurfacewidth, cfnumbercreate(kcfallocatordefault, kcfnumbersint32type, &width)); cfdictionarysetvalue(dict, kiosurfaceheight, cfnumbercreate(kcfallocatordefault, kcfnumbersint32type, &height)); cfdictionarysetvalue(dict, kiosurfacepixelformat, cfnumbercreate(kcfallocatordefault, kcfnumbersint32type, pixelformat)); cfdictionarysetvalue(dict, kiosurfaceallocsize, cfnumbercreate(kcfallocatordefault, kcfnumbersint32type, &size)); iosurfaceref destsurf = iosurfacecreate(dict); iosurfaceacceleratorref outacc; iosurfaceacceleratorcreate(null, 0, &outacc); cfdictionaryref ed = (__bridge cfdictionaryref)[nsdictionary dictionarywithobjectsandkeys: nil]; iosurfaceacceleratortransfersurface(outacc, screensurface, destsurf, ed, null); uint32_t aseed; iosurfaceunlock(screensurface, kiosurfacelockreadonly, &aseed); cgdataproviderref provider = cgdataprovidercreatewithdata(null, iosurfacegetbaseaddress(destsurf), (width*height*4), null); cgimageref cgimage=cgimagecreate(width, height, 8, 8*4, iosurfacegetbytesperrow(destsurf), cgcolorspacecreatedevicergb(), kcgimagealphanoneskipfirst | kcgbitmapbyteorder32little, provider, null, yes, kcgrenderingintentdefault); uiimage *image = [uiimage imagewithcgimage: cgimage]; uiimagewritetosavedphotosalbum(image, self_object, nil, nil); cgimagerelease(cgimage); cfrelease(destsurf);
after combining code 2 places, able save photo photo album (with application in background).
iosurfaces - artefacts in video , unable grab video surfaces
https://github.com/tomcool420/smframework/blob/master/smfscreencapture.m
please try out , let me know if works you.
-(void)savephoto { iomobileframebufferconnection connect; kern_return_t result; iosurfaceref screensurface = null; io_service_t framebufferservice = ioservicegetmatchingservice(kiomasterportdefault, ioservicematching("appleh1clcd")); if(!framebufferservice) framebufferservice = ioservicegetmatchingservice(kiomasterportdefault, ioservicematching("applem2clcd")); if(!framebufferservice) framebufferservice = ioservicegetmatchingservice(kiomasterportdefault, ioservicematching("appleclcd")); result = iomobileframebufferopen(framebufferservice, mach_task_self(), 0, &connect); result = iomobileframebuffergetlayerdefaultsurface(connect, 0, &screensurface); uint32_t aseed; iosurfacelock(screensurface, kiosurfacelockreadonly, &aseed); uint32_t width = iosurfacegetwidth(screensurface); uint32_t height = iosurfacegetheight(screensurface); //int m_width = 320; //int m_height = 480; cfmutabledictionaryref dict; int pitch = width*4, size = width*height*4; int bpe=4; char pixelformat[4] = {'a','r','g','b'}; dict = cfdictionarycreatemutable(kcfallocatordefault, 0, &kcftypedictionarykeycallbacks, &kcftypedictionaryvaluecallbacks); cfdictionarysetvalue(dict, kiosurfaceisglobal, kcfbooleantrue); cfdictionarysetvalue(dict, kiosurfacebytesperrow, cfnumbercreate(kcfallocatordefault, kcfnumbersint32type, &pitch)); cfdictionarysetvalue(dict, kiosurfacebytesperelement, cfnumbercreate(kcfallocatordefault, kcfnumbersint32type, &bpe)); cfdictionarysetvalue(dict, kiosurfacewidth, cfnumbercreate(kcfallocatordefault, kcfnumbersint32type, &width)); cfdictionarysetvalue(dict, kiosurfaceheight, cfnumbercreate(kcfallocatordefault, kcfnumbersint32type, &height)); cfdictionarysetvalue(dict, kiosurfacepixelformat, cfnumbercreate(kcfallocatordefault, kcfnumbersint32type, pixelformat)); cfdictionarysetvalue(dict, kiosurfaceallocsize, cfnumbercreate(kcfallocatordefault, kcfnumbersint32type, &size)); iosurfaceref destsurf = iosurfacecreate(dict); void* outacc; iosurfaceacceleratorcreate(null, 0, &outacc); iosurfaceacceleratortransfersurface(outacc, screensurface, destsurf, dict, null); iosurfaceunlock(screensurface, kiosurfacelockreadonly, &aseed); cfrelease(outacc); cgdataproviderref provider = cgdataprovidercreatewithdata(null, iosurfacegetbaseaddress(destsurf), (width * height * 4), null); cgimageref cgimage=cgimagecreate(width, height, 8, 8*4, iosurfacegetbytesperrow(destsurf), cgcolorspacecreatedevicergb(), kcgimagealphanoneskipfirst |kcgbitmapbyteorder32little, provider, null, yes, kcgrenderingintentdefault); uiimage *img = [uiimage imagewithcgimage:cgimage]; uiimagewritetosavedphotosalbum(img, self, nil, nil); // relevant part of code //cvpixelbuffercreatewithbytes(null, width, height, kcvpixelformattype_32bgra, iosurfacegetbaseaddress(destsurf), iosurfacegetbytesperrow(destsurf), null, null, null, &samplebuffer); }
Comments
Post a Comment