One Quickie


Non-chunky high-DPI image drawing (NSImage->General)
If you load NSImages from random files and draw them larger than they say they are, sometimes you get a really chunky, pixellated display for images that have a high DPI rather than a smooth interpolation (or even using all those extra pixels due to the high DPI). This is because (I think) that the image says that it's 100x100, even though you have 1000x1000 pixels available, and Cocoa decides to scale up only 100x100 pixels.

One way to hack around it is to tell the image to use the pixel size of the underlying image representation:

    NSImage *image;
    image = [[NSImage alloc] initWithContentsOfFile: path];

    NSBitmapImageRep *rep = [[image representations] objectAtIndex: 0];
    // If you think you might get something other than a bitmap image representation,
    // check for it here.

    NSSize size = NSMakeSize ([rep pixelsWide], [rep pixelsHigh]);
    [image setSize: size];



borkware home | products | miniblog | rants | quickies | cocoaheads
Advanced Mac OS X Programming book

webmonster@borkware.com