Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

printf

macrumors regular
Original poster
Aug 27, 2008
105
0
my googling has turned up nothing (that works).

i want to save the UIImage using UIImageJPEGRepresentation, but i'm unable to get it to work in in the iPhone simulator. it doesn't crash, but it doesn't write the image either...

Code:
NSData * imageData = UIImageJPEGRepresentation(image.image, 1.0);
NSString *path = [[NSString alloc] initWithString:@"~/Library/Application Support/iPhone Simulator/User/Media/DCIM/100APPLE/SAVE_IMAGE_TEST1.JPG"];
[imageData writeToFile:path atomically:YES];

first off, is it even possible to do this in simulator?? if so, can i please get an example? ideally it would save to the Photo Library that can be accessed in the simulator as i want this to be as close to the real deal as possible, but anywhere on my hard disk will work if this isn't possible.

second, i'm using the imagePickerController to grab an image and then edit it, but when i save i want to save to the current directory where the image came from, but use a different file name of course. how to i get the current directory?

thanks!
 
I think you might want the UIImageWriteToSavedPhotosAlbum() function..

However, the reason your data isn't getting written to (at minimum) is because you're using a relative path via ~ and you need to use absolute paths. For testing just user the full path, e.g. /Users/you/Library/... etc.
 
I think you might want the UIImageWriteToSavedPhotosAlbum() function..

However, the reason your data isn't getting written to (at minimum) is because you're using a relative path via ~ and you need to use absolute paths. For testing just user the full path, e.g. /Users/you/Library/... etc.

hi kainjow,

the problem i'm having with UIImageWriteToSavedPhotosAlbum, is that first, i don't know how to specify a name for the saved image, but more importantly, it saves the image as a highly compressed JPEG even when i call use UIIMagePNGRepresentatin to create the image data. here's my code:

Code:
//will result in highly compressed (very lossy image)
NSData * imageData = UIImagePNGRepresentation(image.image);
UIImage *theImage = [UIImage imageWithData:imageData];
UIImageWriteToSavedPhotosAlbum(theImage, self, nil, nil);
 
Old thread, I know, but I just saw on the Cocoa-dev mailing list that UIImageWriteToSavedPhotosAlbum() saves as a JPEG, so transparency will be lost. Looks like there's no workaround.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.