ios - app crash on importing greater than 8 megapixel Image to uiimageview -


our app crashing on importing images greater 8 megapixels on iphone. @ times high memory usage too.

by way images trying import greater 8 megapixels , not huge 4000 x 3000 (12 megapixel).photos taken using iphone camera 3264 x 2448 (8 megapixels).

here our memory report

when importing 8 megapixel image

enter image description here


when importing 12 megapixel image

enter image description here

huge difference in memory usage. have idea why there's huge difference in memory usage , solution of this?

(we'll using images edit,filter,process etc).

here our code

- (void)imagepickercontroller:(uiimagepickercontroller *)picker didfinishpickingmediawithinfo:(nsdictionary *)info {     uiimage *selectedimage=[info objectforkey:uiimagepickercontrolleroriginalimage];      //scaling uiimage      uiimage *scaledimage=[[uiimage alloc]init];     if ((selectedimage.size.width>3264) && (selectedimage.size.height>2448))     {         uigraphicsbeginimagecontextwithoptions(cgsizemake(selectedimage.size.width/2, selectedimage.size.height/2), no, 0.0);         nslog(@" height %f",selectedimage.size.height);         nslog(@" width %f",selectedimage.size.width);          [selectedimage drawinrect:cgrectmake(0, 0,selectedimage.size.width/2 ,selectedimage.size.height/2 )];        scaledimage = uigraphicsgetimagefromcurrentimagecontext();          uigraphicsendimagecontext();          nslog(@" height %f",scaledimage.size.height);         nslog(@" width %f",scaledimage.size.width);           visualeffectimageview.image=scaledimage;         backgroundimageview.image=scaledimage;         foregroundimageview.image=scaledimage;     }     else     {     visualeffectimageview.image=selectedimage;     backgroundimageview.image=selectedimage;     foregroundimageview.image=selectedimage;     }    if(ui_user_interface_idiom()==uiuserinterfaceidiomphone)     {         [picker dismissviewcontrolleranimated:yes completion:nil];     }     else     {           [popovercontroller dismisspopoveranimated:yes];          [self popovercontrollerdiddismisspopover:popovercontroller];   }  } 

_mgl9114.jpg image file.

_mgl9114 size 3744px × 5616px

if import file ios project , render in uiview.it take 108mb memory.because ios render uiimage in realtime,if image high quality,it use high memory cache image data.

if want reduce it,you should load uiimage in backend , output compressed version. take 23mb memory.

even if want edit image,just render effect on compressed version.when users complete edit,you process effects in backend(don't render original version) , save original version user's library.

nsstring * imagebundle = [[nsbundle mainbundle] pathforresource:@"_mgl9114" oftype:@"jpg"]; nsdata * imagedata = [[nsdata alloc]initwithcontentsoffile:imagebundle]; uiimage * handleimage = [uiimage imagewithdata:imagedata];  uigraphicsbeginimagecontextwithoptions(cgsizemake(handleimage.size.width/10, handleimage.size.height/10), no, 0.0); [handleimage drawinrect:cgrectmake(0, 0,handleimage.size.width/10 ,handleimage.size.height/10 )]; uiimage *newimage = uigraphicsgetimagefromcurrentimagecontext(); uigraphicsendimagecontext();   uiimageview * imageview = [[uiimageview alloc]initwithframe:cgrectmake(0, 0, handleimage.size.width/10, handleimage.size.height/10)]; [imageview setimage:newimage];  [self.view addsubview:imageview]; 

Comments

Popular posts from this blog

php - failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request -

java - How to filter a backspace keyboard input -

java - Show Soft Keyboard when EditText Appears -