/** * Specify size compress picture (picture will compress deformation) * * @param image original * @param size compress size * * @return Compressed picture*/-(uiimage*) Originimage: (UIImage *) Image scaletosize: (cgsize) size{//Create a bitmap context//and set it to the context that is currently being useduigraphicsbeginimagecontext (size); //draw a picture that changes size[Image Drawinrect:cgrectmake (0,0, Size.width, Size.Height)]; //create a resized picture from the current contextuiimage* Scaledimage =Uigraphicsgetimagefromcurrentimagecontext (); //make the current context out of the stackUigraphicsendimagecontext (); //returns the new resized image returnscaledimage;}/** * equal to zoom picture to crop the specified area picture * * @param image original * @param size clipping range * * @return cropped picture*/-(UIImage *) Compressimagewith: (UIImage *) Image scaletosize: (cgsize) size{//Original WidthCGFloat imagewidth =Image.size.width; //Original HeightCGFloat imageheight =Image.size.height; //Zoom ratioCGFloat Widthscale = imagewidth/Size.width; CGFloat Heightscale= ImageHeight/Size.Height; //Create a bitmap context//and set it to the context that is currently being usedUigraphicsbeginimagecontext (Cgsizemake (Size.width, size.height)); //Horizontal screen Picture if(Widthscale >Heightscale) {[Image Drawinrect:cgrectmake (0,0, ImageWidth/Heightscale, Size.Height)]; } Else{//Portrait screen Picture[Image Drawinrect:cgrectmake (0,0, Size.width, ImageHeight/Widthscale)]; } //create a resized picture from the current contextUIImage *newimage =Uigraphicsgetimagefromcurrentimagecontext (); //make the current context out of the stackUigraphicsendimagecontext (); returnNewImage; }
IOS Zoom Picture Common methods