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

发布于 2024-10-29 18:32:12 字数 326 浏览 12 评论 0原文

我正在使用iPhone应用程序来嵌入/提取JPEG文件中的数据。我想让用户能够将所得图像复制到剪贴板上,但是当我将结果的jpeg复制到剪贴板时,我使用的代码将其掩盖为PNG。

我正在使用下面的代码,我有什么可以做的,以确保jpeg的copy and粘贴有点复制和粘贴?

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

提前致谢!

I'm working on an iPhone app to embed/extract data in jpeg files. 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.

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?

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

Thanks in advance!

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

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

发布评论

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

评论(2

私藏温柔 2024-11-05 18:32:12

我终于弄清楚了这一点。

// 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];

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];
岁月如刀 2024-11-05 18:32:12
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 
    }

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

祝你好运!

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 , i m using same code

Good Luck !!!!

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