Banding/smoothing problem with drawing angled gradients.
Banding/smoothing problem with drawing angled gradients.
- Subject: Banding/smoothing problem with drawing angled gradients.
- From: Phi Le <email@hidden>
- Date: Thu, 19 Mar 2009 20:57: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