如何将UIImage数据复制到剪贴板/ UIPasteboard?我该如何测试呢?

时间:2011-07-11 06:47:20

标签: ios cocoa-touch copy-paste uipasteboard

我尝试使用以下代码在单击菜单中的“复制”项目时将图像数据复制到UIPasteboard

UIPasteboard *gpBoard = [UIPasteboard generalPasteboard];
[[gpBoard setData:UIImageJPEGRepresentation(imgView.image, 1.0) forPasteboardType:UIPasteboardTypeListImage];

我必须为forPasteboardType发送哪个参数:以及如何在复制数据后进行测试?

3 个答案:

答案 0 :(得分:25)

这更容易:

[UIPasteboard generalPasteboard].image = imgView.image;

要再次拍摄照片:

UIImage *image = [UIPasteboard generalPasteboard].image;

答案 1 :(得分:3)

我尝试了上述内容,出于某种原因,它在iOS 7,8上大受欢迎。有时候它有效,有时它不会,即系统没有显示"粘贴"选项。

这对我来说非常适合所有设备和所有iOS

    UIPasteboard *pasteboard = [UIPasteboard generalPasteboard];
    NSData *imgData = UIImagePNGRepresentation([UIImage imageNamed:@"test.png"]);
    [pasteboard setData:imgData forPasteboardType:[UIPasteboardTypeListImage objectAtIndex:0]];

答案 2 :(得分:0)

斯威夫特:

UIPasteboard.generalPasteboard().image = imageToCopy
相关问题