Cannot Opening Image using NSOpenPanel
-
24-09-2022 - |
Domanda
I need to open image using NSOpenPanel. I did it using the following code:
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];
When I run my app, there's opening file dialog, i select my jpg image, and there's nothing. I don't see my image in image view as expected. Help me please.
Nessuna soluzione corretta
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow