• 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
Banding/smoothing problem with drawing angled gradients.
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Banding/smoothing problem with drawing angled gradients.


  • Subject: Banding/smoothing problem with drawing angled gradients.
  • From: Phi Le <email@hidden>
  • Date: Mon, 16 Mar 2009 13:19:43 -0700

Hello,

I want to draw angled gradients with multiple sharp transitions using
NSGradient. I am not getting very smooth transitions between the
colors. Please take a look at my attachment to see the problem.   Are
there solutions without having to use NSShading?

Thanks,

Phi


<code>
- (void) drawRect: (NSRect) rect {
	[[NSGraphicsContext currentContext] setShouldAntialias:YES];
	float locs[8] = {0.0, 0.25, 0.3, 0.35, 0.5, 0.6, 0.7, 1.0 };
	NSMutableArray * colors = [[NSMutableArray alloc] init];

	[colors addObject: [NSColor blackColor]];

	[colors addObject: [NSColor blackColor]];
	[colors addObject: [NSColor greenColor]];
	[colors addObject: [NSColor blackColor]];

	[colors addObject: [NSColor blackColor]];
	[colors addObject: [NSColor redColor]];
	[colors addObject: [NSColor blackColor]];

	[colors addObject: [NSColor blackColor]];

	NSColorSpace * space = [NSColorSpace genericRGBColorSpace];
	NSGradient * gradient = [[NSGradient alloc] initWithColors:colors
atLocations:&locs colorSpace: space];

	float angle = 0;
	for(int r = 0; r < 5; r++) {
		for(int c = 0; c < 3; c++) {
			[gradient drawInRect:NSMakeRect(c*200, r*90, 180, 80) angle: angle];
			angle += 5;
		}
	}
}
</code>

Attachment: gradients.png
Description: PNG image

_______________________________________________

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

  • Prev by Date: Re: Automatically replacing part of text in a text label
  • Next by Date: Re: Double Initialize - is that how it should be?
  • Previous by thread: Re: Bindings: which object+property is being edited?
  • Next by thread: Banding/smoothing problem with drawing angled gradients.
  • Index(es):
    • Date
    • Thread