Detailed description of Mask usage in iPhone development applications

Source: Internet
Author: User

IPhone DevelopmentApplication in progressMaskUsage is the content to be introduced in this article, mainly to introduceMask. There is not much content. This article is mainly implemented by code. Let's take a look at the details.

Mask Method

 
 
  1. + (UIImage*) maskImage:(UIImage*)image withMask:(UIImage*)mask {  
  2.  
  3.  CGImageRef imgRef = [image CGImage];CGImageRef maskRef = [mask CGImage];
  4. CGImageRef actualMask = CGImageMaskCreate(CGImageGetWidth(maskRef),CGImageGetHeight(maskRef),
  5. CGImageGetBitsPerComponent(maskRef),CGImageGetBitsPerPixel(maskRef),
  6. CGImageGetBytesPerRow(maskRef),CGImageGetDataProvider(maskRef), 
  7. NULL, false);CGImageRef masked = CGImageCreateWithMask(imgRef, 
  8. actualMask);return [UIImage imageWithCGImage:masked];   

Resize Images

 
 
  1. + (UIImage *) resizeImage:(UIImage *)image size:(CGSize)newSize {UIGraphicsBeginImageContext(newSize);  
  2. [image drawInRect:CGRectMake(0, 0, newSize.width, newSize.height)];  
  3. UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();UIGraphicsEndImageContext();  
  4. return newImage;   

Method call/: Convert the original image to 120x120. In this step, the size of the original image is determined.

 
 
  1. UIImage * newImg = [Utils resizeImage: orgImg size: CGSizeMake (120,120)];
  2. UIImage * maskImg = [UIImage imageNamed: @ "mask.png"];
  3. // Obtain the parts of the mask.
  4. NewImg = [ImageUtils maskImage: newImg withMask: maskImg];
  5. // Start cropping (Clip) Slices

Summary: DetailsIPhone DevelopmentApplication in progressMaskI hope this article will help you with your usage!

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.