iOS Learning-compress pictures (change the width of the picture)

Source: Internet
Author: User

Compressing the picture, the size of the picture is inconsistent with the width we expect, we can handle it as we want it to be wide.

Pass in the picture you want to change, and the new size

-(uiimage*) Imagewithimage: (uiimage*) Image scaledtosize: (cgsize) newsize{//Create a graphics image contextUigraphicsbeginimagecontext (newSize);//// new Size[image Drawinrect:cgrectmake (0,0// Get the new image from the contextuiimage* newimage =// End the Context// Return the new Image. NewImage;}           

When a button comes with a imageview, if the picture is automatically compressed, it causes distortion (sometimes not as small as we expect). If I'm in iOS learning-uibutton's ImageView and Titlelabel

Wide high enough is no problem, but I put the button of the Titlelabel.font set Small (12), Wide height set small (height of 30 or less) when there is a problem, is not think the picture behind is too big,

And the picture of the width of the high and not directly change, then we can first put the picture to do a small point, in addition on OK.

UIImage *buttonimage = [UIImage imagenamed:image];    // compress picture size   buttonimage = [self imagewithimage:buttonimage scaledtosize:cgsizemake ()]; CGFloat buttonimageviewwidth = cgimagegetwidth (buttonimage.cgimage); CGFloat buttonimageviewheight = cgimagegetheight (buttonimage.cgimage); NSString *buttontitle = title; Uifont *buttontitlefont = [Uifont boldsystemfontofsize:12.0f];        

iOS Learning-compress pictures (change the width of the picture)

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.