1

I'm working on an OSX app and I'm trying to get an image from a NSUrl. It works well, but with some images (not every image), the size is not good.

For example, I'm trying to get a 1600 * 1200 image from the NSUrl, but when I NSlog the value I get the result is 384 * 288, so the quality is decreased. But this bug is not on every images.

I have tried this with PNG and JPG, the result is the same, some are resized, some are not.

I dont want the image to be resized because the quality is my main concern.

Here's my code :

 - (IBAction)loadImageAction:(id)sender {
    NSArray* fileTypes = [[NSArray alloc] initWithObjects:@"jpg",@"png", nil];
    NSOpenPanel *panel = [NSOpenPanel openPanel];
    [panel setCanChooseFiles:YES];
    [panel setCanChooseDirectories:NO];
    [panel setAllowsMultipleSelection:NO];
    [panel setAllowedFileTypes:fileTypes];

    NSInteger clicked = [panel runModal];
    if (clicked == NSFileHandlingPanelOKButton) {
        for (NSURL *url in [panel URLs]) {
            NSImage *img = [[NSImage alloc] initWithContentsOfURL:url];
            NSLog(@"IMAGE FROM URL : image.width = %f, image.height = %f", img.size.width, img.size.height);
            if (img != nil) {
                [_imageView setImage:img]; // just a NSImageView to display the image
            }
        }
    }
}

0 Answers0