Copy image to cardboard jpeg to png transcodes

I am working on an iPhone application for inserting / extracting data in jpeg files. I want to give the user the ability to copy the resulting image to the clipboard, but the code I use hides the resulting jpeg in png when it is copied to the clipboard.

I am using the code below, is there anything I can do to make sure this is a bitwise copy and jpeg insert?

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

Thanks in advance!

+5
source share
2 answers

I finally figured it 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];
+5
source
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 
    }

Fully working code, I m using the same code

Good luck !!!!

-1

All Articles