如何将 UIView 中绘制的像素与 UIImageView 中的图像组合并将其另存为新图像? [英] How to combine drawn pixels in a UIView with the image in a UIImageView and save it as a new image?

查看:23
本文介绍了如何将 UIView 中绘制的像素与 UIImageView 中的图像组合并将其另存为新图像?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道如何将 UIView 中绘制的像素与 UIImageView 中的图像组合并将其另存为新图像?我不知道该怎么做.

I am wondering how to combine drawn pixels in a UIView with the image in a UIImageView and save it as a new image? I have no clue how to go about this.

如果有人能指出我正确的方向,我会很高兴.

If anyone could point me in the right direction, I would love it.

谢谢!

推荐答案

查看 Quartz 2D.具体来说,CGContextDrawImage() 可用于加载图像,在此上下文上绘制您想要的任何内容,然后您可以CGBitmapContextCreateImage() 创建一个CGImageRef 您可以使用 UIImageimageWithCGImage 从中创建图像.最后,您使用 UIImagePngRepresentation()UIImageJPEGRepresentation() 获取 NSData,然后您可以将其与 writeToFile 一起使用.

Check out Quartz 2D. Specifically, CGContextDrawImage() can be used to load an image, draw whatever you want on this context, and then you can CGBitmapContextCreateImage() to create a CGImageRef from which you can create an image with UIImage's imageWithCGImage. Finally, you use UIImagePngRepresentation() or UIImageJPEGRepresentation() to get a NSData that you can then use writeToFile with.

这篇关于如何将 UIView 中绘制的像素与 UIImageView 中的图像组合并将其另存为新图像?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆