[IOS] Image Compression & amp; save View as content Img

Source: Internet
Author: User

[IOS] Image Compression & amp; save View as content Img

1. Image Compression

Encapsulation Method

+ (UIImage*)imageWithImageSimple:(UIImage*)image scaledToSize:(CGSize)newSize{    // Create a graphics image context    UIGraphicsBeginImageContext(newSize);        // Tell the old image to draw in this new context, with the desired    // new size    [image drawInRect:CGRectMake(0,0,newSize.width,newSize.height)];        // Get the new image from the context    UIImage* newImage = UIGraphicsGetImageFromCurrentImageContext();        // End the context    UIGraphicsEndImageContext();        // Return the new image.    return newImage;}

// Screen and compress UIImage * snapshot = [UIImage imageWithCGImage: [AppDelegate screenShots]. CGImage scale: 1 orientation: UIImageOrientationLeft]; _ updataImg = [AppDelegate imageWithImageSimple: snapshot scaledToSize: CGSizeMake (snapshot. size. width/3, snapshot. size. height/3)];

2. Save View as content Img

-(Void) savetoLocal {_ moreVC. hidden = YES; UIImage * saveimg = [self saveImage]; encrypt (saveimg, self, @ selector (imageSavedToPhotosAlbum: didFinishSavingWithError: contextInfo :), nil);}-(UIImage *) saveImage {UIGraphicsBeginImageContext (CGSizeMake (self. view. bounds. size. width, self. view. bounds. size. height-20); // save self. view content [self. view. layer renderInContext: UIGraphicsGetCurrent Context ()]; UIImage * viewImage = alert (); UIGraphicsEndImageContext (); return viewImage;}-(void) imageSavedToPhotosAlbum :( UIImage *) image didFinishSavingWithError :( NSError *) error contextInfo :( void *) contextInfo {NSString * message = @ "Haha"; if (! Error) {message = @ "successfully saved to album";} else {message = [error description];} NSLog (@ "message is % @", message );}


Related Article

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.