IOS Zoom Picture Common methods

Source: Internet
Author: User

/** * 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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.