将图像复制到UIPasteboard

时间:2011-02-24 22:37:58

标签: iphone

如何将图像复制到UIPasteboard?

我只看过文字示例。

3 个答案:

答案 0 :(得分:12)

如果查看Apple's Documentation for UIPasteboard,您会发现可以使用'setImage:`方法将图像复制到粘贴板,例如:

[[UIPasteboard generalPasteboard] setImage:myImage];

或者如果您想添加多张图片:

[[UIPasteboard generalPasteboard] setImages:[NSArray arrayWithObjects:myFirstImage, mySecondImage, nil]];

或者如果您已经拥有图像数组:

[[UIPasteboard generalPasteboard] setImages:myImagesArray];

(以my开头的所有上述变量应替换代码中的变量)

答案 1 :(得分:1)

使用这个.....这里newImage是UIImage。

UIPasteboard *pasteBoard = [UIPasteboard pasteboardWithName:UIPasteboardNameGeneral create:NO];
pasteBoard.persistent = YES;
NSData *data = UIImagePNGRepresentation(newImage);
[pasteBoard setData:data forPasteboardType:(NSString *)kUTTypePNG];     
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"sms:00"]];

答案 2 :(得分:1)

实际上,您只需使用以下代码即可:

UIPasteboard *pasteboard = [UIPasteboard generalPasteboard];
pasteboard.string = @"my string";
pasteboard.image = [UIImage imageNamed:@"my image"];