Re: NSImage initWithContentsOfURL
Re: NSImage initWithContentsOfURL
- Subject: Re: NSImage initWithContentsOfURL
- From: Matt Judy <email@hidden>
- Date: Wed, 23 Jan 2002 17:30:02 -0800
John Nikolai wrote:
>
> image = [[NSImage alloc] initWith
Data:[url resourceDataUsingCache:YES]];
>
> Note that initWithData: is not a class method. At least not in the
> current framework I have installed.
Right, right. My code used to make those calls, but I changed things
around a bit... If you're working with online images, you're eventually
going to find that, if you load an image from the web whose resolution
is higher than 72 dpi, AppKit will draw that image at the higher
resolution, making it appear too small on your display.
The workaround for that problem is to use an NSBitmapImageRep, like this:
// ------------------------------------------------------------------
NSURL *url = [NSURL URLWithString:stringURLOfHiRezImage];
NSBitmapImageRep *imageRep = [[NSBitmapImageRep alloc] initWithData:
[url resourceDataUsingCache:YES]];
NSImage *image = [[NSImage alloc] initWithSize:[comicImageBitmapRep
size]];
[image addRepresentation:imageRep];
// ------------------------------------------------------------------
Now your image will be sized properly.
--Matt Judy