NSImage display quality and zooming
NSImage display quality and zooming
- Subject: NSImage display quality and zooming
- From: also <email@hidden>
- Date: Tue, 27 May 2008 19:37:38 -0500
I've created a custom NSView that displays an image and allows the
user to zoom in and out. The view works in general, but the quality
of the image displayed is not what I expect. When I zoom in even
slightly on a high resolution image (300 dpi, 500x500) the image is
grainy and pixelated. If I do the same in Preview the quality is much
better.
I read in the image (a JPEG) using:
image = [[NSImage alloc] initWithContentsOfURL:url];
I keep a scale factor called imageScale (default 1.0) and draw the
image as follows :
[[NSGraphicsContext currentContext] setImageInterpolation:
NSImageInterpolationHigh];
NSSize viewSize = [self bounds].size;
NSSize imageSize = [image size];
NSAffineTransform* at = [NSAffineTransform transform];
[at scaleBy:imageScale];
imageSize = [at transformSize:imageSize];
NSPoint viewCenter;
viewCenter.x = viewSize.width * 0.50;
viewCenter.y = viewSize.height * 0.50;
NSPoint imageOrigin = viewCenter;
imageOrigin.x -= imageSize.width * 0.50;
imageOrigin.y -= imageSize.height * 0.50;
NSRect destRect;
destRect.origin = imageOrigin;
destRect.size = imageSize;
[image drawInRect:destRect
fromRect:NSZeroRect
operation:NSCompositeSourceOver
fraction:1.0];
I've tried adjusting the NSScale by hand rather than using the
transform, no change. I also tried subclassing an IKImageView. Using
its built in zoom worked ok but I can't draw NSBezierPaths over the
top which I also need for this subclass. Can anyone see what I'm
doing wrong, or suggest a better method?
Thanks,
-Matthew
_______________________________________________
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