Re: How to properly display small, high resolution images?
Re: How to properly display small, high resolution images?
- Subject: Re: How to properly display small, high resolution images?
- From: "Ken Ferry" <email@hidden>
- Date: Sun, 16 Dec 2007 10:20:07 -0800
I'm not sure what the purpose of the code with the comment 'just sets
the dimensions of newSize properly' is.
The 'tempImage' had all the data from the original file. When you
called lockFocus and drew into the new image, that data was thrown
away - all that was left was a bitmap at screen resolution with size
newSize. -lockFocus should be considered a somewhat expensive thing
to do. It's making a new bitmap memory buffer, drawing, and setting
up a context for you to draw into. Sometimes this is genuinely what
you need, but if not, it's churn. It also trashes CG-level caches.
As Glenn suggested, it looks like you probably wanted to draw directly
with the 'templmage' here. The draw methods take a destination rect,
and the image will be scaled to fill it with whatever quality is
available. A caveat: if your image is drawn at _multiple_ resolutions
to the screen, you need to advise NSImage not to optimize itself to
the first context it's drawn into and throw away extra data. This is
done by calling [image setDataRetained:YES]. Then the image may still
create an optimized cache when it is drawn, but all the original data
will be around if it's drawn to a context that doesn't match the
original destination. If the image is infrequently drawn, for example
if it's _only_ redrawn once per different resolution at which it's
rendered, you may want to ask it not to create the cache as well,
which is done with [image setCacheMode:NSImageCacheNever].
-Ken
On Dec 15, 2007 11:33 AM, that guy <email@hidden> wrote:
> Hey all - I'm trying to display a bunch of very small high resolution images, and I'm confused. They render perfectly well (full screen) in Preview or iPhoto, and yet when I do the standard
>
> NSImage* tempImage = [[NSImage alloc] initWithContentsOfFile:filename];
> NSSize newSize;
>
> //snip - just sets the dimensions of newSize properly
> NSImage *scaleImage = [[NSImage alloc] initWithSize:newSize];
> [scaleImage lockFocus];
> [[NSGraphicsContext currentContext] setImageInterpolation:NSImageInterpolationHigh];
> [tempImage drawInRect:NSMakeRect(0, 0, newSize.width, newSize.height) fromRect:NSZeroRect operation:NSCompositeSourceOver fraction:1.0];
> [scaleImage unlockFocus];
> [scaleImage drawInRect:NSMakeRect(screenSize.width/2-newSize.width/2, screenSize.height/2-newSize.height/2, newSize.width, newSize.height) fromRect:NSZeroRect operation:NSCompositeSourceOver fraction:1.0];
>
> , everything ends up horrendously pixellated. The "actual" size of these images is tiny (like 150x150) and yet, as I said, they render in full screen perfectly well.
>
> I also tried "NSImageInterpolationNone" on a lark - no luck. Can anyone give me a hint?
>
>
>
>
>
> ____________________________________________________________________________________
> Looking for last minute shopping deals?
> Find them fast with Yahoo! Search. http://tools.search.yahoo.com/newsearch/category.php?category=shopping
> _______________________________________________
>
> Cocoa-dev mailing list (email@hidden)
>
> Please do not post admin requests or moderator comments to the list.
> Contact the moderators at cocoa-dev-admins(at)lists.apple.com
>
> Help/Unsubscribe/Update your Subscription:
>
> This email sent to email@hidden
>
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden