gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-03 16:16:37 31 4
gpt4 key购买 nike

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];
}
}

关于macos - 如何在 NSPasteBoard cocoa os x 中复制图像?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18124656/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com