【问题标题】:Masking and Reverse Masking in Imageview iosImageview ios中的遮罩和反向遮罩
【发布时间】:2015-03-23 05:28:15
【问题描述】:

我有一个包含 Image 的 Imageview 。还有一个包含兔子形状的面具形状。 我有一个代码给出以下结果。

- (UIImage*)mynewmaskImage:(UIImage *)image withMask:(UIImage *)maskImage {
CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();

CGImageRef maskImageRef = [maskImage CGImage];

// create a bitmap graphics context the size of the image
CGContextRef mainViewContentContext = CGBitmapContextCreate (NULL,320, 380, 8, 0, colorSpace,(CGBitmapInfo) kCGImageAlphaPremultipliedLast);
CGColorSpaceRelease(colorSpace);

if (mainViewContentContext==NULL)
    return NULL;

CGFloat ratio = 0;

ratio = 320/ image.size.width;

if(ratio * image.size.height < 380) {
    ratio = 380/ image.size.height;
}

CGRect rect1  = {{0, 0}, {320,380}};
CGRect rect2  = {{-((image.size.width*ratio)-320)/2 , -((image.size.height*ratio)-380)/2}, {image.size.width*ratio, image.size.height*ratio}};

//  CGContextDrawImage(mainViewContentContext, rect2, image.CGImage);

CGContextClipToMask(mainViewContentContext, rect1, maskImageRef);
CGContextDrawImage(mainViewContentContext, rect2, image.CGImage);
CGImageRef newImage = CGBitmapContextCreateImage(mainViewContentContext);
CGContextRelease(mainViewContentContext);

UIImage *theImage = [UIImage imageWithCGImage:newImage];

CGImageRelease(newImage);

// return the image
return theImage;}

上面的代码给出了这个结果。

但我想要以下结果(如反向屏蔽)。

这怎么可能。请帮助我。 谢谢。

【问题讨论】:

  • 我希望图像像(PicsArt 应用程序)一样反转。我上面的代码给出了第一个图像(我上传)结果。问题在于第二个。
  • 透明背景上的黑兔呢?
  • 你应该只是能够反转兔子的图像并得到你想要的结果。
  • 请上传您的代码。
  • @DevinM .但是如何反转兔子图像请告诉我..

标签: ios objective-c uiimageview mask


【解决方案1】:

你应该看看 blendMode。试试这样:

[rabbitImage drawInRect:rect
              blendMode:kCGBlendModeDestinationOut
                alpha:1.0];

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-02-09
    • 1970-01-01
    • 2014-12-07
    • 2018-01-06
    • 1970-01-01
    • 1970-01-01
    • 2012-11-06
    相关资源
    最近更新 更多