简体   繁体   English

iOS -> 将 2 UIImageView 保存到 cameraRoll

[英]iOS -> saving 2 UIImageView to cameraRoll

i have two layers of UIImageView, upper one is partly transparent, second in is 'background'.我有两层 UIImageView,上一层是部分透明的,第二层是“背景”。 I want to save them both like user see them from front into cameraRoll for user's use.我想将它们都保存起来,就像用户从前面看到它们一样保存到 cameraRoll 中供用户使用。 The problem is writing it in way:问题是这样写:

if(gridUpperLayer == transparent) {drawGridLowerLayer} 
else {drawGridUpperLayer} 

will be very slow (and i dont know how to implement it).会很慢(而且我不知道如何实现它)。 Anybody has idea how to do it in faster way..?任何人都知道如何以更快的方式做到这一点..? Best would be with example but i would be grateful for anything ^^ Cheers and thank you in advance!最好举个例子,但我会很感激任何事情^^干杯,提前谢谢你!

You can do this by rendering the CALayer into an image for the UIView that contains both of the images.您可以通过将 CALayer 渲染到包含两个图像的 UIView 的图像中来做到这一点。 The following code would look like:以下代码如下所示:

UIGraphicsBeginImageContext(containerView.frame.size);
[containerView.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *anImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();

//save anImage to disk //将图像保存到磁盘

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM