Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iPhone - Save UIImage to desktop on simulator

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 :)

like image 907
nax_ Avatar asked Apr 26 '11 17:04

nax_


People also ask

How do I use iPhone as Xcode simulator?

To run your app in Simulator, choose an iOS simulator—for example, iPhone 6 Plus, iPad Air, or iPhone 6 + Apple Watch - 38mm—from the Xcode scheme pop-up menu, and click Run. Xcode builds your project and then launches the most recent version of your app running in Simulator on your Mac screen, as shown in Figure 1-1.

How do you simulate an iPhone on a Mac?

Simulating Different iOS DevicesOpen the iOS simulator, if it's not already open. From the Hardware menu, select Device, and then select the type of device you want to simulate. The simulator window will change to match the dimensions of the device you selected.

Is iOS simulator a virtual machine?

It's neither a Virtual Machine nor an Emulator. It's a simulator, in another words it's a standard mac application which mimic the behaviour of iOS devices. It mimics most of the features of an actual devices, but lacks some major features. So you need to use a real device for testing some of the real world scenarios.


1 Answers

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];

Edit: 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);

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

like image 178
Chris Wagner Avatar answered Nov 09 '22 01:11

Chris Wagner