zoukankan      html  css  js  c++  java
  • 给UIImage添加蒙版

    http://stackoverflow.com/questions/17448102/ios-masking-an-image-keeping-retina-scale-factor-in-account

    I want to mask an image by passing another image as mask. I am able to mask the image but the resulting image doesn't look good. It is jagged at borders.

    I guess the problem is related to retina graphics. The scale property for the two images are different as:

    1. The image from which I want to mask has a scale value 1. This image generally has a resolution greater than 1000x1000 pixels.
    2. The image according to which I want the resulting image(image having black and white colors only) has scale value 2. This image is generally of resolution 300x300 pixels. 

    The resulting image has a scale value of 1.

    The code I am using is:

    + (UIImage*) maskImage:(UIImage *)image withMask:(UIImage *)maskImage {
    
    CGImageRef maskRef = maskImage.CGImage;
    
    CGImageRef mask = CGImageMaskCreate(CGImageGetWidth(maskRef),
                                        CGImageGetHeight(maskRef),
                                        CGImageGetBitsPerComponent(maskRef),
                                        CGImageGetBitsPerPixel(maskRef),
                                        CGImageGetBytesPerRow(maskRef),
                                        CGImageGetDataProvider(maskRef), NULL, false);
    
    
    CGImageRef masked = CGImageCreateWithMask([image CGImage], mask);
    CGImageRelease(mask);
    UIImage *maskedImage = [UIImage imageWithCGImage:masked ];
    CGImageRelease(masked);
    return maskedImage;
    }
    

    How can I get a masked image which follows retina scale?

  • 相关阅读:
    已经连接到空闲例程的解决方法
    SQLplus命令中导出数据
    Oracle设置时间格式
    Oracle热备份
    多元化控制文件
    ORA28000: the account is locked
    Windows 7 如何删除 Windows.old 文件夹
    Linux常用命令之文件命令
    Linux 常用命令之进程管理
    Python中的apply,filter和map函数
  • 原文地址:https://www.cnblogs.com/gatsbywang/p/4463912.html
Copyright © 2011-2022 走看看