Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Copying an image to pasteboard transcodes jpeg to png

I'm working on an iPhone app to embed/extract data in jpeg files. I want to give the user the ability to copy the resulting image to the clipboard, but the code I'm using coverts the resulting jpeg into a png when it gets copied to the clipboard.

I'm using the code below, is there anything I can do to ensure it is a bit by bit copy and paste of the jpeg?

// copy to clipboard
UIPasteboard *pasteboard = [UIPasteboard generalPasteboard];
pasteboard.image = [UIImage imageNamed:@"output.jpg"];

Thanks in advance!

like image 847
Ben Holland Avatar asked Oct 12 '22 09:10

Ben Holland


1 Answers

I finally figured this one out.

// copy to clipboard
UIPasteboard *pasteboard = [UIPasteboard generalPasteboard];
NSData *data = [NSData dataWithContentsOfFile:filePath];
[pasteboard setData:data forPasteboardType:@"public.jpeg"];

...

// copy from clipboard
UIPasteboard *pasteboard = [UIPasteboard generalPasteboard];
NSData *data = [pasteboard dataForPasteboardType:@"public.jpeg"];
NSString  *copyPath = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents/image.jpg"];
[data writeToFile:copyPath atomically:YES];
like image 80
Ben Holland Avatar answered Oct 14 '22 00:10

Ben Holland