ios - Memory consumption spikes when resizing, rotating and cropping images on iPhone -
i have "imagemanipulator" class performs cropping, resizing , rotating of camera images on iphone.
at moment, works expected keep getting few huge spikes in memory consumption cause app crash.
i have managed isolate problem part of code check current image orientation property , rotate accordingly uiimageorientationup
. image bitmap context , save disk.
this doing:
cgaffinetransform transform = cgaffinetransformidentity; // check orientation , set transform accordingly... transform = cgaffinetransformtranslate(transform, self.size.width, 0); transform = cgaffinetransformscale(transform, -1, 1); // create bitmap context image passed can perform rotation cgcontextref ctx = cgbitmapcontextcreate(null, self.size.width, self.size.height, cgimagegetbitspercomponent(self.cgimage), 0, cgimagegetcolorspace(self.cgimage), cgimagegetbitmapinfo(self.cgimage)); // rotate context cgcontextconcatctm(ctx, transform); // draw image context cgcontextdrawimage(ctx, cgrectmake(0,0,self.size.height,self.size.width), self.cgimage); // grab bitmap context , save disk...
even after trying scale image down half or 1/4 of size, still seeing spikes wondering if there different / more efficient way rotation done above?
thanks in advance replies. rog
if saving jpeg, guess alternative approach save image as-is , set rotation whatever you'd manipulating exif metadata? see example this post. simple effective, if have hold image payload bytes in memory ;)
Comments
Post a Comment