简体   繁体   English

将图像复制到粘贴板将jpeg转码为png

[英]Copying an image to pasteboard transcodes jpeg to png

I'm working on an iPhone app to embed/extract data in jpeg files. 我正在开发一个iPhone应用程序来嵌入/提取jpeg文件中的数据。 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. 我想让用户能够将生成的图像复制到剪贴板,但是我正在使用的代码将生成的jpeg转换为png,当它被复制到剪贴板时。

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? 我正在使用下面的代码,有什么我可以做的,以确保它是一点一滴地复制和粘贴的jpeg?

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

Thanks in advance! 提前致谢!

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];
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 , im using same code 完全正常工作的代码,我使用相同的代码

Good Luck !!!! 祝好运 !!!!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM