• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
NSImage display quality and zooming
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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

  • Follow-Ups:
    • Re: NSImage display quality and zooming
      • From: Dmitri Goutnik <email@hidden>
    • Re: NSImage display quality and zooming
      • From: Graham Cox <email@hidden>
  • Prev by Date: Re: Cocoa Classes from C++?
  • Next by Date: Re: NSImage display quality and zooming
  • Previous by thread: Re: Cocoa Classes from C++?
  • Next by thread: Re: NSImage display quality and zooming
  • Index(es):
    • Date
    • Thread