用图像掩盖图像?

时间:2013-06-10 16:29:55

标签: iphone ios objective-c xcode ipad

不使用代码:

    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) - 为什么?

在Apple文档中: 而不是传递使用CGImageMaskCreate函数创建的图像蒙版, 你提供了一个从Quartz图像创建函数创建的图像。

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

但不起作用......嗯

log Info myImageMask:
宽度:440
身高:292
BitsPerComponent:8
BitsPerPixel:8
BytesPerRow:440
BitmapInfo:0
ColorSpace :( kCGColorSpaceICCBased; kCGColorSpaceModelMonochrome; Dot Gain 20%)

渲染内容:2

1 个答案:

答案 0 :(得分:0)

导致此问题的唯一方法是在{$ 1}}中将myImage作为null。让所有代码看起来都很好。

localResultImage = CGImageCreateWithMask(myImage, localMaskImage);

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

localResultImage = CGImageCreateWithMask([myImage CGImage], localMaskImage);
相关问题