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

发布于 2024-11-19 12:54:12 字数 324 浏览 4 评论 0原文

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

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

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

I tried to use the following code to copy the Image data to UIPasteboard on click of the Copy item in the menu.

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

Which parameter i have to send for forPasteboardType:, and how to test after copying the data?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

陈年往事 2024-11-26 12:54:12

这要容易得多:

[UIPasteboard generalPasteboard].image = imgView.image;

要再次取出图像:

UIImage *image = [UIPasteboard generalPasteboard].image;

It's a lot easier:

[UIPasteboard generalPasteboard].image = imgView.image;

To get the image out again:

UIImage *image = [UIPasteboard generalPasteboard].image;
め七分饶幸 2024-11-26 12:54:12

我尝试了上述方法,但由于某种原因,它在 iOS 7,8 上时好时坏。有时有效,有时无效,即系统不显示“粘贴”选项。

这对我来说在所有设备和所有 iOS 上都一致有效

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

I tried the above and for some reason it's a hit and miss on iOS 7,8. Sometimes it works and sometimes it doesn't i.e. system doesn't show "Paste" option.

This worked for me consistenly on all devices and all iOS

    UIPasteboard *pasteboard = [UIPasteboard generalPasteboard];
    NSData *imgData = UIImagePNGRepresentation([UIImage imageNamed:@"test.png"]);
    [pasteboard setData:imgData forPasteboardType:[UIPasteboardTypeListImage objectAtIndex:0]];
标点 2024-11-26 12:54:12

斯威夫特:

UIPasteboard.generalPasteboard().image = imageToCopy

Swift:

UIPasteboard.generalPasteboard().image = imageToCopy
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文