• 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: 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

  • Follow-Ups:
    • Re: Banding/smoothing problem with drawing angled gradients.
      • From: Graham Cox <email@hidden>
    • Re: Banding/smoothing problem with drawing angled gradients.
      • From: mm w <email@hidden>
    • Re: Banding/smoothing problem with drawing angled gradients.
      • From: Kyle Sluder <email@hidden>
  • Prev by Date: Re: Get the list of Places in Finder?
  • Next by Date: Re: NSTimer & Runloop questions
  • Previous by thread: Banding/smoothing problem with drawing angled gradients.
  • Next by thread: Re: Banding/smoothing problem with drawing angled gradients.
  • Index(es):
    • Date
    • Thread