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: glenn andreas <email@hidden>
- Date: Sat, 15 Dec 2007 14:51:37 -0600
On Dec 15, 2007, at 1:33 PM, that guy 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?
The problem is that with high resolution images, NSImage's size will
return the size in points (72/inch), which is where I'm guessing you
get "newSize" from. Since you draw the image in that lower resolution
value, and then draw that expanded, you get pixelization.
So, for example (to make the numbers easy), if it is 720dpi 1" x 1"
image (i.e. 720px x 720px), [tempImage size] will return (72,72) - you
make a new image at that size, draw the 720px image into that 72px
size, and then scale the 72px size up.
Instead of making a new image, you could start by just using the
"tempImage" and draw that (and if you need to make changes to it,
you'll need to iterate through the NSImageRep's inside NSImage to find
the highest resolution one and base your tempImage's size based on that)
Glenn Andreas email@hidden
<http://www.gandreas.com/> wicked fun!
quadrium | prime : build, mutate, evolve, animate : the next
generation of fractal art
_______________________________________________
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