如何在 NSPasteBoard cocoa os x 中复制图像?

2023-12-21

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。

任何帮助将不胜感激


 - (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];
        }
    }
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

如何在 NSPasteBoard cocoa os x 中复制图像? 的相关文章

随机推荐