0

我需要使用 NSOpenPanel 打开图像。我使用以下代码做到了:

NSOpenPanel *open = [NSOpenPanel openPanel];
NSArray *fileTypes = [[NSArray alloc] initWithObjects:@"jpg", @"gif", @"png", nil];
NSURL *filePath = [[NSURL alloc] init];

[open setCanChooseFiles:YES];
[open setAllowedFileTypes:fileTypes];
[open setAllowsMultipleSelection:NO];

if ([open runModal] == NSOKButton) {
    filePath = [open URL];
    NSLog(@"%@", [filePath path]);
}

NSImage *selectedImage = [[NSImage alloc] initWithData:[NSData dataWithContentsOfFile:[filePath path]]];
[imageView setImage:selectedImage];

当我运行我的应用程序时,会打开文件对话框,我选择我的 jpg 图像,但什么也没有。我没有按预期在图像视图中看到我的图像。请帮帮我。

4

0 回答 0