5

It seems that the OS chooses whether to use a PNG or JPEG for reasons unknown. In my case, I want a JPEG sent (via mail, twitter, etc.) but I tend to get a very large PNG.

If I subclass UIActivityItemProvider and return an NSURL pointing to a file that I created myself by writing a JPEG to disk using UIImageJPEGRepresentation, I can of course get a JPEG. However using an NSURL causes other issues (one of them being the inability to use iMessage as a target). Is there any way to use a UIImage, but specify that you would prefer a certain file format? (I'm quite sure the answer is NO, but want to check.)

akaru
  • 6,299
  • 9
  • 63
  • 102

2 Answers2

10

Actually it just worked to pass in the NSData of the JPEG representation as the activity item.

NSData *data = UIImageJPEGRepresentation(image, 0.6);
UIActivityViewController *activityController = [[UIActivityViewController alloc] initWithActivityItems:@[data]];
                                                                                 applicationActivities:nil];
stigi
  • 6,661
  • 3
  • 40
  • 50
  • good one, saved a lot of time. :) In my case I wanted to keep the images PNG but they were being converted to JPG while sharing so I sent the PNG data here :) +1 – Ahsan Ebrahim Khatri Mar 09 '16 at 11:26
-5

Looks like the answer is indeed NO.

akaru
  • 6,299
  • 9
  • 63
  • 102