iPhone - 在模拟器上将UIImage保存到桌面 [英] iPhone - Save UIImage to desktop on simulator

查看:157
本文介绍了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.

感谢您的帮助:)

推荐答案

以下内容应该为您提供帮助已启动... myImage 是一个UIImage对象。

The following should get you started... myImage is an UIImage object.

NSFileManager *fileManager = [NSFileManager defaultManager];
NSData *myImageData = UIImagePNGRepresentation(myImage);
[fileManager createFileAtPath:@"/Users/Me/Desktop/myimage.png" contents:myImageData attributes:nil];

编辑:注意到你想要一个JPG图像,你可以得到 NSData 使用 UIImageJPEGRepresentation() 所以:

Just noticed you wanted a JPG image, you can get the NSData representation of a JPG using UIImageJPEGRepresentation() so:

NSData *myImageData = UIImageJPEGRepresentation(myImage, 1.0);

注意:这对快速和肮脏的测试很有用,但我建议学习如何写入应用程序的文档目录,然后使用Finder在那里找到文件。模拟器中应用程序文档目录的示例路径是:

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

这篇关于iPhone - 在模拟器上将UIImage保存到桌面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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