不要使用代码:
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 图像创建功能之一创建的图像。
用作 mask (但不是 Quartz 图像 mask )的图像的源样本作为 alpha 值操作。
……
在这种情况下,假设图 11-6 中所示的图像是使用 Quartz 图像创建函数之一创建的,例如 CGImageCreate。
但不起作用......嗯
日志信息 myImageMask:
宽度:440
高度:292
每组件位数:8
每像素位数:8
每行字节数:440
位图信息:0
ColorSpace:(kCGColorSpaceICCBased;kCGColorSpaceModelMonochrome;网点增益 20%)
渲染意图:2
最佳答案
唯一可能导致该问题的是 myImage
如null
在下一行。其余所有代码看起来都不错。
localResultImage = CGImageCreateWithMask(myImage, localMaskImage);
如果 myImage 是 UIImage 类的对象,那么您应该使用以下行:
localResultImage = CGImageCreateWithMask([myImage CGImage], localMaskImage);
关于iphone - 用图像掩盖图像?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17028634/