Reputation: 2309
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!
Upvotes: 5
Views: 6065
Reputation: 1806
NSPasteboard *pboard = [NSPasteboard generalPasteboard];
[pboard declareTypes: [NSMutableArray arrayWithObject:
NSTIFFPboardType] owner: nil];
[pboard setData:[imgView.image TIFFRepresentation] forType:NSTIFFPboardType];
NSData *data = [[NSPasteboard generalPasteboard] dataForType:NSPasteboardTypeTIFF];
if (data) {
// Do your stuff here
}
Completely working code , i m using same code
Good Luck !!!!
Upvotes: -1
Reputation: 2309
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];
Upvotes: 5