Question

Ever since I updated to 10.7.4 I started having issues with my NSImage code. When I read out the representations of an image, select the Bitmap image representation and try to write it out to a PNG file I receive an error.

Therefore I tried doing it through the 'regular' way, with the following errors:

enter image description here

My first guess would be removing the broken version of libPNG and replacing it with a working one. Any suggestions on how I should tackle this problem? I could try compiling an old version of libPNG and read out the bitmap image and write it out myself. Love it how the quality of OSX degraded to the level of windows vista in Lion.

And yes, OSX uses libPNG: http://d.pr/i/nOEX

To clarify it a bit more, here is my test build code:

NSImage *image = [[NSImage alloc] initWithContentsOfFile:@"/Users/jabwd/Desktop/Icons/4099.ico"];

    NSLog(@"%@",[image representations]);
    NSImageRep *biggest = nil;
    for(NSImageRep *rep in [image representations])
    {
        if( ! biggest )
        {
            biggest = rep;
        }
        else if( [rep size].width >= [biggest size].width && [rep size].height >= [biggest size].height )
        {
            biggest = rep;
        }
    }

    if( biggest && [biggest isKindOfClass:[NSBitmapImageRep class]] )
    {
        NSBitmapImageRep *bitmap = (NSBitmapImageRep *)biggest;
        NSData *data = [bitmap representationUsingType:NSPNGFileType properties:nil];
        [data writeToFile:@"/Users/jabwd/Desktop/test.png" atomically:false];
    }

As you can see I assume there are multiple representations in the image. I can do this in this case because there is a certain type of icons I'm loading, its a private project and won't get into the hands of some users => there is a certain task for another bigger application I have which needs to be automated.

Was it helpful?

Solution

Looks like ImageIO.framework has a few bugs in 10.7.4, its the same libPNG version found on 10.7.3. Using an automator script to convert the images to jpegs before converting them to pngs seems to be working.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top