iPhone - 将 UIImage 保存到模拟器上的桌面
我目前正在开发模拟器。 我想将 UIImage 保存到桌面上的 jpg 文件中。
看来我的路径或其他问题有问题。
感谢您的帮助 :)
I'm currently working on the simulator.
I'd like to save an UIImage to a jpg file, on my desktop.
It seems that I have a problems with paths or something.
Thank you for your help :)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
下面应该帮助您开始...
myImage
是一个 UIImage 对象。编辑:刚刚注意到您想要 JPG 图像,您可以使用
UIImageJPEGRepresentation()
所以:注意: 这对于快速和肮脏的测试很有用,但我建议学习如何写入文档您的应用程序的目录,然后使用 Finder 查找那里的文件。模拟器中应用程序文档目录的示例路径为:
/Users/Me/Library/Application Support/iPhone Simulator/4.3/Applications/1E2C2C81-1ED6-4DC9-CDD0-CA73FB56501F/Documents
The following should get you started...
myImage
is an UIImage object.Edit: Just noticed you wanted a JPG image, you can get the
NSData
representation of a JPG usingUIImageJPEGRepresentation()
so:Note: This is useful for quick and dirty testing but I would suggest learning how to write to the documents directory of your app and then using Finder to find the files there. An example path to an application's document directory in the simulator is:
/Users/Me/Library/Application Support/iPhone Simulator/4.3/Applications/1E2C2C81-1ED6-4DC9-CDD0-CA73FB56501F/Documents
尝试转到
cd /Users/{您的用户名}/Library/Application\ Support/iPhone\ Simulator/4.3/Applications/{application id}/Documents/
替换
{您的用户名} 是您的 mac 用户名,
{application id}
是您的应用程序 GUID(随机)。您还可以将4.3
更改为您的应用所针对的版本Try going to
cd /Users/{your username}/Library/Application\ Support/iPhone\ Simulator/4.3/Applications/{application id}/Documents/
Replace
{your username}
with your mac username and{application id}
is your application GUID (random). You also may change4.3
to what ever version your app is built for对于Swift,
像这样调用,
For Swift,
Call like this,
该模拟器模拟沙盒应用程序,但由于它位于 Mac 上,因此您可以访问存储该应用程序及其所有文件的目录。因此,在您的应用程序中,如果您可以弄清楚如何将数据写入文件(在应用程序的沙箱内),那么您可以使用 Finder 来定位目录并找到文件。这有帮助还是我错过了什么?
The simulator emulates a sandboxed application, but since it's on your Mac, you can access the directory in which the application and all its files are stored. So, in your app, if you can figure out how to write the data to a file (within the app's sandbox), then you can use the Finder to locate the directory and locate the file. Does this help or am I missing something?