【问题标题】:Masking an Image with an Image?用图像掩盖图像?
【发布时间】:2013-06-06 09:20:41
【问题描述】:

不要使用代码:

    CGImageRef localResultImage;
    CGImageRef localMaskImage;

    size_t width = CGImageGetWidth(myImageMask);
    size_t height = CGImageGetHeight(myImageMask);
    size_t bitsPerComponent = CGImageGetBitsPerComponent(myImageMask);
    size_t bitsPerPixel = CGImageGetBitsPerPixel(myImageMask);
    size_t bytesPerRow = CGImageGetBytesPerRow(myImageMask);
    CGDataProviderRef provider = CGImageGetDataProvider(myImageMask);
    CGBitmapInfo bitmapInfo = CGImageGetBitmapInfo(myImageMask);
    CGColorSpaceRef space = CGImageGetColorSpace(myImageMask);
    CGColorRenderingIntent intent = CGImageGetRenderingIntent(myImageMask);

    localMaskImage = CGImageCreate(width,
                                   height,
                                   bitsPerComponent,
                                   bitsPerPixel,
                                   bytesPerRow,
                                   space,
                                   bitmapInfo,
                                   provider,
                                   NULL,
                                   TRUE,
                                   intent);

    localResultImage = CGImageCreateWithMask(myImage, localMaskImage);

    CGContextDrawImage(myContext, dirtyRect, localResultImage);

localResultImage = (null) - 为什么?

在苹果文档中: 而不是传递使用函数 CGImageMaskCreate 创建的图像掩码, 您提供从 Quartz 图像创建函数之一创建的图像。

用作遮罩(但不是 Quartz 图像遮罩)的图像的源样本作为 Alpha 值操作。 …… 在这种情况下,假设图 11-6 中所示的图像是使用 Quartz 图像创建函数之一创建的,例如 CGImageCreate。

但是不行……嗯

日志信息 myImageMask:
宽度:440
身高:292
BitsPerComponent:8
每像素位数:8
字节数:440
位图信息:0
颜色空间:(kCGColorSpaceICCBased;kCGColorSpaceModelMonochrome;网点增益 20%)

渲染意图:2

【问题讨论】:

  • +1 获得漂亮的代码/字体。
  • 是 myImageMask 和 myImage != null 吗?
  • myImageMask == true / myImage == true / localMaskImage == true

标签: iphone ios objective-c xcode ipad


【解决方案1】:

可能导致问题的唯一方法是在以下行中将myImage 设置为null。其余所有代码看起来都不错。

localResultImage = CGImageCreateWithMask(myImage, localMaskImage);

如果 myImage 是 UIImage 类的对象,那么您应该使用以下行:

localResultImage = CGImageCreateWithMask([myImage CGImage], localMaskImage);

【讨论】:

  • myImage: myImageMask: localMaskImage: localResultImage: (null)
  • myImage 和所有对象图像都是 CGImageRef。所有对象都完美地显示在视图中,除了 -localResultImage。
猜你喜欢
  • 1970-01-01
  • 2011-01-11
  • 1970-01-01
  • 2015-11-08
  • 1970-01-01
  • 2018-12-09
  • 2017-12-06
  • 2020-11-19
  • 1970-01-01
相关资源
最近更新 更多