简体   繁体   English

在iOS上将UIView导出为png

[英]Exporting a UIView to a png on iOS

I have 100's of images that I need to format on a UIView. 我有100幅需要在UIView上格式化的图像。 I need to be able to access screenshots of these images remotely so I figure the most convenient way is to prerender them as .png's and just upload them directly. 我需要能够远程访问这些图像的屏幕截图,所以我认为最方便的方法是将它们预渲染为.png并直接上传。 They won't be unique for each user so no point having each user upload there own, that could get ugly quickly. 它们对于每个用户而言都不是唯一的,因此让每个用户上传自己的内容毫无意义,这可能很快就会变得丑陋。

Can anybody tell me how I could go about doing this in a Mac or iOS application? 有人可以告诉我如何在Mac或iOS应用程序中执行此操作吗?

I'm currently using UIGraphicsGetImageFromCurrentImageContext to create a png in memory but I have no idea how to physically save it as a file that exists outside the application. 我目前正在使用UIGraphicsGetImageFromCurrentImageContext在内存中创建png,但是我不知道如何将其物理保存为应用程序外部存在的文件。

Use UIImagePNGRepresentation to get the data from the UIImage . 使用UIImagePNGRepresentation可以从UIImage获取数据。 Then use writeToFile:atomically: to save the data to disk or NSURLConnection to send the data to a web service. 然后使用writeToFile:atomically:将数据保存到磁盘或使用NSURLConnection将数据发送到Web服务。

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

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