iOS加载动态层掩码(即,层掩码在代码外部提供) [英] iOS load dynamic layer mask (i.e. layer mask is provided outside the code)
问题描述
情况:想要对图像应用感兴趣的相框,并且相框被实现为图层蒙版,是否可以通过在obj-C代码之外加载相框模板来动态构建图层蒙版,以便我可以改变框架层而不触摸代码?
Situation: want to apply interesting photo frame to images, and the photo frame is implemented as layer mask, is it possible to dynamically build the layer mask by load a photo frame template outside of the obj-C code so that I can change the frame layer without ever touching the code?
最终结果将是这样的。 http:// a3 .mzstatic.com / us / r1000 / 106 / Purple / 9e / b9 / 9b / mzl.rdrrpcgr.320x480-75.jpg ,除了照片边缘/框架是在应用程序外部动态加载,而不是构建 - 到应用程序。
the end result will be something like this. http://a3.mzstatic.com/us/r1000/106/Purple/9e/b9/9b/mzl.rdrrpcgr.320x480-75.jpg, except the photo edge/frame is dynamically loaded outside of the app, rather than built-into the app.
理想情况下,想要轻松地创建一个相框在photoshop作为png文件,其中黑色像素这里将允许完全透明度,然后我可以在iOS应用程序中将此相框加载为框架图层将允许下面的图层完全通过掩模层为黑色的位置...
Ideally, would like to easily create a photo frame in photoshop as png file where the black pixel here will allow full transparency.. and then I can load this photo frame in the iOS app as the frame layer will allow the layer underneath to fully go through wherever the mask layer is black...
推荐答案
+ (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);
return [UIImage imageWithCGImage:masked];
}
然后你可以使用这个方法与从一个URL加载的UIImage。
Then you could use this method with a UIImage you load from a URL.
网址可以投放不同的UIImage,或者可以采用要加载UIImageMask的参数。这是否回答你的问题?
The URL could serve a different UIImage, or could take a parameter for which UIImageMask to load. Does this answer your question?
这篇关于iOS加载动态层掩码(即,层掩码在代码外部提供)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!