0

I want to save the last clicked image saved in Photos gallery to document directory. How can i achieve it.?

Sushobhit
  • 305
  • 4
  • 18
  • I think you mean by memory disk space. Am I right with that assumption? The only explanation that I can think of is that images in the photos library are compressed. – ok404 Jan 15 '16 at 08:31
  • @ok404 - yes i mean by memory disk space. have you any solution for this..? – Sushobhit Jan 15 '16 at 08:43
  • Why duplicate: http://stackoverflow.com/questions/34740631/why-jpeg-file-save-via-writetofile-using-uiimagejpegrepresentation-method-have ? – Larme Jan 15 '16 at 11:06

2 Answers2

0

In your code change NSData *dataForJPEGFile = UIImageJPEGRepresentation(mimage, 1.0); to

NSData *dataForJPEGFile = UIImageJPEGRepresentation(mimage, 0.5);

This code 0.5 means 50% of your image will compress.

    - (void)saveImageToDocumentsDirectory:(UIImage *)mimage withFileName:(NSString *)fileName {
                NSData *dataForJPEGFile = UIImageJPEGRepresentation(mimage, 0.5);
                [dataForJPEGFile writeToFile:[self getDirectoryFilePath:fileName] atomically:YES];
}
Ramesh_T
  • 1,251
  • 8
  • 19
0

Make sure the saved photo in your PhotosAlbum is correct size and quality. iOS has an issue, see link: UIImageWriteToSavedPhotosAlbum saves to wrong size and quality

For some pictures, the PNG format will be smaller than JPG format. You can try to save picture via UIImagePNGRepresentation.

Community
  • 1
  • 1
Harrison Xi
  • 766
  • 1
  • 5
  • 23