2013-08-08 2 views
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 Service를 통해이 이미지를 iPhone으로 보내고 있습니다.NSPasteBoard 코코아 OS X에서 이미지를 복사하는 방법?

어떤 도움

답변

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

복사 이미지가 맥에서 괜찮 이해할 수있을 것이다,하지만 난 맥에없는 아이폰에 이미지를 붙여 넣을. 너의 ans 주셔서 감사. –