3
I have tried this one , but not working

NSPasteboard *pboard  = [NSPasteboard generalPasteboard];
[pboard declareTypes: [NSMutableArray arrayWithObject:
                       NSTIFFPboardType] owner: nil];
[pboard setData:[imgView.image TIFFRepresentation] forType:
NSData *data = [[NSPasteboard generalPasteboard] dataForTyp
if (data) {
    imgView.image=[imgView.image initWithData:data];
}

我正在通过 Apple Bonjour 服务将此图像发送到 iPhone。

任何帮助将不胜感激

4

2 回答 2

8
 - (IBAction)copy:sender {        
        NSImage *image = [imageView image];
        if (image != nil) {
            NSPasteboard *pasteboard = [NSPasteboard generalPasteboard];
            [pasteboard clearContents];
            NSArray *copiedObjects = [NSArray arrayWithObject:image];
            [pasteboard writeObjects:copiedObjects];
        }
    }

 - (IBAction)paste:sender {   
        NSPasteboard *pasteboard = [NSPasteboard generalPasteboard];
        NSArray *classArray = [NSArray arrayWithObject:[NSImage class]];
        NSDictionary *options = [NSDictionary dictionary];
        BOOL ok = [pasteboard canReadObjectForClasses:classArray options:options];
        if (ok) {
            NSArray *objectsToPaste = [pasteboard readObjectsForClasses:classArray options:options];
            NSImage *image = [objectsToPaste objectAtIndex:0];
            [imageView setImage:image];
        }
    }
于 2013-08-08T11:27:02.917 回答
0

为了快速,将图像复制到粘贴板:

let pb = NSPasteboard.general
pb.clearContents()
pb.writeObjects([nsImage])
于 2018-06-21T14:43:03.203 回答