This Code demonstrates how to narrow down the uiimage
@ Implementation uiimage (extras) <br/> # pragma mark-<br/> # pragma mark scale and crop image <br/>-(uiimage *) imagebyscalingandcroppingforsize :( cgsize) targetsize <br/> {<br/> uiimage * sourceimage = self; <br/> uiimage * newimage = nil; <br/> cgsize imagesize = sourceimage. size; <br/> cgfloat width = imagesize. width; <br/> cgfloat Height = imagesize. height; <br/> cgfloat targetwidth = targetsize. width; <br/> cgfloat targetheight = targetsize. height; <br/> cgfloat scalefactor = 0.0; <br/> cgfloat scaledwidth = targetwidth; <br/> cgfloat scaledheight = targetheight; <br/> cgpoint thumbnailpoint = cgpointmake (0.0, 0.0); <br/> If (cgsizeequaltosize (imagesize, targetsize) = No) <br/>{< br/> cgfloat widthfactor = targetwidth/width; <br/> cgfloat heightfactor = targetheight/height; <br/> If (widthfactor> heightfactor) <br/> scalefactor = widthfactor; // scale to fit height <br/> else <br/> scalefactor = heightfactor; // scale to fit width <br/> scaledwidth = width * scalefactor; <br/> scaledheight = height * scalefactor; <br/> // center the image <br/> If (widthfactor> heightfactor) <br/> {<br/> thumbnailpoint. y = (targetheight-scaledheight) * 0.5; <br/>}< br/> else <br/> If (widthfactor <peightfactor) <br/>{< br/> thumbnailpoint. X = (targetwidth-scaledwidth) * 0.5; <br/>}< br/> uigraphicsbeginimagecontext (targetsize ); // This will crop <br/> cgrect thumbnailrect = cgrectzero; <br/> thumbnailrect. origin = thumbnailpoint; <br/> thumbnailrect. size. width = scaledwidth; <br/> thumbnailrect. size. height = scaledheight; <br/> [sourceimage drawinrect: thumbnailrect]; <br/> newimage = uigraphicsgetimagefromcurrentimagecontext (); <br/> If (newimage = nil) <br/> nslog (@ "cocould not scale image"); <br/> // pop the context to get back to the default <br/> uigraphicsendimagecontext (); <br/> return newimage; <br/>}< br/>