使用添加的叠加将照片保存到照片库

我正在制作一个应用程序,用户拍摄照片,覆盖图像放在图像上,然后用户可以保存图像或上传到Facebook或其他网站。

我已经设法让应用程序拍照,并使覆盖我使用UIImageView ,放置在照片的顶部。

我不确定我可以如何将图像,覆盖图,一个文件,照片库或Facebook导出。

这应该给你的想法。 虽然这个代码可能需要调整一两个。 (我承认我没有运行它。)

你的UIImageView的基础层可以将自己渲染成一个CoreGraphics位图上下文(当然这将包括所有的子层),然后它可以为你提供一个新的UIImage

 UIImage *finalImage; // Get the layer CALayer *layer = [myImageView layer]; // Create a bitmap context and make it the current context UIGraphicsBeginImageContext(layer.bounds.size); // Get a reference to the context CGContextRef ctx = UIGraphicsGetCurrentContext(); // Ask the layer to draw itself [layer drawInContext:ctx]; // Then ask the context itself for the image finalImage = UIGraphicsGetImageFromCurrentImageContext(); // Finally, pop the context off the stack UIGraphicsEndImageContext(); 

这些函数全部在UIKit函数参考中描述。

还有一个稍微复杂一点的方式,让你更好地控制颜色等东西,这包括创build一个CGBitmapContext并获取一个CGImageRef ,从中可以再次生成一个UIImage 。 在“Quartz 2D Programming Guide ”中的“创build位图graphics上下文”一节中进行了描述。