• 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 ignoring interpolation: Is this a bug?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

NSImage ignoring interpolation: Is this a bug?


  • Subject: NSImage ignoring interpolation: Is this a bug?
  • From: Scott Stevenson <email@hidden>
  • Date: Fri, 24 Nov 2006 18:15:31 -0800

Playing around with NSImage I noticed that it's pretty brutal to scaling bitmap images. It looks like it's ignoring the interpolation setting on the context.


This draws the images in a relatively pixelated manner:

	[[NSGraphicsContext currentContext]
		setImageInterpolation: NSImageInterpolationHigh];

NSSize size = { 256, 160 };
float center = [self bounds].size.width * 0.50;
float middle = [self bounds].size.height * 0.50;
NSPoint origin = { center - size.width * 0.50, middle + size.height * 0.5 };


	NSString * path = @"/Library/Desktop Pictures/Aqua Blue.jpg";
	NSImage * image = [[NSImage alloc] initByReferencingFile:path];

	[image setScalesWhenResized:YES];
	[image setSize: size];
	[image compositeToPoint:origin operation:NSCompositeSourceOver];

	[image release];


This draws it perfectly:

	[[NSGraphicsContext currentContext]
		setImageInterpolation: NSImageInterpolationHigh];

	NSSize size = { 256, 160 };
	float center = [self bounds].size.width  * 0.50;
	float middle = [self bounds].size.height * 0.50;
	NSPoint origin = { center - size.width * 0.50, middle - size.height };

	NSString * path = @"/Library/Desktop Pictures/Aqua Blue.jpg";
	NSImage * image = [[NSImage alloc] initByReferencingFile:path];

	NSAffineTransform * transform = [NSAffineTransform transform];
	[transform translateXBy:1 yBy:160];
	[transform set];

	NSImageRep * bitmap = [image bestRepresentationForDevice:nil];
	[bitmap setSize: size];
	[bitmap drawAtPoint:origin];

	[image release];


The second version not only requires more acrobatics but you lose the ability to control compositing and alpha. I can't think of any reason NSImage would not want to draw smooth bitmaps.


Am I missing something or is this a bug? I feel like I didn't have this problem in previous versions of Mac OS X. I'm on 10.4.8 intel.

Thanks,

    - Scott

_______________________________________________

Cocoa-dev mailing list (email@hidden)

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 ignoring interpolation: Is this a bug?
      • From: Mark Onyschuk <email@hidden>
    • Re: NSImage ignoring interpolation: Is this a bug?
      • From: Scott Stevenson <email@hidden>
  • Prev by Date: Re: How can I copy/duplicate an existing NSTextField?
  • Next by Date: Re: How can I copy/duplicate an existing NSTextField?
  • Previous by thread: Re: How can I copy/duplicate an existing NSTextField?
  • Next by thread: Re: NSImage ignoring interpolation: Is this a bug?
  • Index(es):
    • Date
    • Thread