【问题标题】:Copying Images to the UIPasteboard将图像复制到 UIPasteboard
【发布时间】:2011-02-24 22:37:58
【问题描述】:

如何将图像复制到 UIPasteboard?

我只看到了文本示例。

【问题讨论】:

    标签: iphone


    【解决方案1】:

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

    [[UIPasteboard generalPasteboard] setImage:myImage];
    

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

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

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

    [[UIPasteboard generalPasteboard] setImages:myImagesArray];
    

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

    【讨论】:

    • 嘿,你能告诉我任何演示如何实现
    • 我有所有方法,但我不知道如何实施
    • 你有任何来自实现的演示。
    【解决方案2】:

    使用这个.....这里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"]];
    

    【讨论】:

      【解决方案3】:

      其实,你可以简单地使用这些代码:

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

      【讨论】:

        猜你喜欢
        • 2011-12-01
        • 2015-02-03
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多