如何在NSPasteBoard可可OS X中复制图像? [英] how to copy image in NSPasteBoard cocoa os x?

查看:154
本文介绍了如何在NSPasteBoard可可OS X中复制图像?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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 Service将这张图片发送到iPhone。

i am sending this image to iPhone via Apple Bonjour Service.

任何帮助将不胜感激

推荐答案

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

这篇关于如何在NSPasteBoard可可OS X中复制图像?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆