5

我正在开发一个 iPhone 应用程序来在 jpeg 文件中嵌入/提取数据。我想让用户能够将生成的图像复制到剪贴板,但是我使用的代码在将生成的 jpeg 复制到剪贴板时将其转换为 png。

我正在使用下面的代码,我能做些什么来确保它是 jpeg 的一点点复制和粘贴吗?

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

提前致谢!

4

2 回答 2

5

我终于想通了这一点。

// 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];
于 2011-04-07T02:11:05.897 回答
-1
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 
    }

完全工作的代码,我使用相同的代码

祝你好运 !!!!

于 2013-08-13T09:11:27.253 回答