Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to save image in jpg or png format in iphone?

I am taking an image from UIImageView and this image I am creating programmatically.Now I want to save this image in jpg or png format in Resource folder.Can anyone know how can I save image in jpg or png format?

Thanks in advance!

like image 929
Sunil Kumar Sahoo Avatar asked May 25 '11 07:05

Sunil Kumar Sahoo


People also ask

How do I get my iPhone to save pictures as JPEGs?

Go to File and select Export. Next, go to the Format menu and choose JPG as the new file format for the selected photos. Finally, click Save to convert and save the pictures.

Are iPhone pictures PNG or JPG?

Screenshots i.e pictures of the iPhone's screen, are taken in PNG format. It's a pretty universal format that all computers and most all devices understand and can display.

How do I save as JPG or PNG?

Go to File > Save as and open the Save as type drop-down menu. You can then select JPEG and PNG, as well as TIFF, GIF, HEIC, and multiple bitmap formats. Save the file to your computer and it will convert.


1 Answers

This should work:

NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask, YES);
NSString *docs = [paths objectAtIndex:0];
NSString* path =  [docs stringByAppendingFormat:@"/image1.jpg"];

NSData* imageData = [NSData dataWithData:UIImageJPEGRepresentation(imageView.image, .8)];
NSError *writeError = nil;

if(![imageData writeToFile:path options:NSDataWritingAtomic error:&writeError]) {
    NSLog(@"%@: Error saving image: %@", [self class], [writeError localizedDescription]);
}
like image 87
skorulis Avatar answered Sep 23 '22 06:09

skorulis