14

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

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

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

4

3 回答 3

28

这要容易得多:

[UIPasteboard generalPasteboard].image = imgView.image;

要再次获取图像:

UIImage *image = [UIPasteboard generalPasteboard].image;
于 2011-07-11T06:52:13.957 回答
3

我尝试了上述方法,由于某种原因,它在 iOS 7,8 上很受欢迎。有时它工作,有时它不,即系统不显示“粘贴”选项。

这在所有设备和所有 iOS 上都对我有用

    UIPasteboard *pasteboard = [UIPasteboard generalPasteboard];
    NSData *imgData = UIImagePNGRepresentation([UIImage imageNamed:@"test.png"]);
    [pasteboard setData:imgData forPasteboardType:[UIPasteboardTypeListImage objectAtIndex:0]];
于 2016-03-08T16:54:18.120 回答
1

迅速:

UIPasteboard.generalPasteboard().image = imageToCopy
于 2016-08-17T16:52:59.610 回答