【发布时间】:2011-02-24 22:37:58
【问题描述】:
如何将图像复制到 UIPasteboard?
我只看到了文本示例。
【问题讨论】:
标签: iphone
如何将图像复制到 UIPasteboard?
我只看到了文本示例。
【问题讨论】:
标签: iphone
如果您查看Apple's Documentation for UIPasteboard,您会发现可以使用 'setImage:` 方法将图像复制到粘贴板,例如:
[[UIPasteboard generalPasteboard] setImage:myImage];
或者如果你想添加多张图片:
[[UIPasteboard generalPasteboard] setImages:[NSArray arrayWithObjects:myFirstImage, mySecondImage, nil]];
或者如果您已经拥有图像数组:
[[UIPasteboard generalPasteboard] setImages:myImagesArray];
(上面所有以my 开头的变量都应替换为代码中的变量)
【讨论】:
使用这个.....这里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"]];
【讨论】:
其实,你可以简单地使用这些代码:
UIPasteboard *pasteboard = [UIPasteboard generalPasteboard];
pasteboard.string = @"my string";
pasteboard.image = [UIImage imageNamed:@"my image"];
【讨论】: