4

Apple の例である CocoaDragAndDrop を調べました。画像を NSImageView にドラッグし、ビュー間で画像をドラッグする方法を理解しています。ただし、画像を Finder にドロップしたときに画像をドラッグしてファイルに保存する方法はまだわかりません。

誰か私に例を挙げてもらえますか?

4

2 に答える 2

9

私はついにそれを行う方法を見つけました。そして、Githubでデモを書きました

于 2011-10-20T03:16:35.227 に答える
-2
-(IBAction)saveImageButtonPushed:(id)sender
{
    NSLog(@"saveImageButtonPushed");

    NSBitmapImageRep *rep;
    NSData *data;
    NSImage *image;

    [self lockFocus];
    rep = [[NSBitmapImageRep alloc] initWithFocusedViewRect:[self frame]];
    [self unlockFocus];

    image = [[[NSImage alloc] initWithSize:[rep size]] autorelease];
    [image addRepresentation:rep];

    data = [rep representationUsingType: NSPNGFileType properties: nil];
        //save as png but failed
    [data writeToFile: @"asd.png" atomically: NO];

        //save as pdf, succeeded but with flaw
    data = [self dataWithPDFInsideRect:[self frame]];
    [data writeToFile:@"asd.pdf" atomically:YES];
}
//......
@end
于 2011-10-16T02:51:05.620 に答える