• 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
How to highlight an image with transparency [SOLUTION]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

How to highlight an image with transparency [SOLUTION]


  • Subject: How to highlight an image with transparency [SOLUTION]
  • From: John Blackburn <email@hidden>
  • Date: Mon, 14 Jan 2002 17:10:46 -0800

With Andrew's instruction, here's a working result:

-(void)drawImage:(NSImage*)theImage atPoint:(NSPoint)where asSelected:(BOOL)selected
{
NSRect sourceRect = NSMakeRect(0,0,[theImage size].width,[theImage size].height);
if (selected)
{
NSImage* image = [[NSImage alloc] initWithSize:[theImage size]];
[image lockFocus];
[theImage compositeToPoint:NSZeroPoint operation:NSCompositeCopy];
[[NSColor colorWithCalibratedWhite:0.0 alpha:0.5] set];
NSRectFillUsingOperation(sourceRect, NSCompositeSourceAtop);
[image unlockFocus];

[image drawAtPoint:where fromRect:sourceRect operation:NSCompositeSourceAtop fraction:1.0];
[image release];
}
else
[theImage drawAtPoint:where fromRect:sourceRect operation:NSCompositeSourceOver fraction:1.0];
}

John Blackburn

On Monday, January 14, 2002, at 01:04 PM, Andrew Platzer wrote:

On Monday, January 14, 2002, at 12:25 , John Blackburn wrote:
What's the proper composite for highlighting an image which contains transparency? NSCompositePlusDarker seems the logical choice, but it draws black for transparent pixels in the image. I've tried all of the combinations of the composite modes I can think of, but none work exactly right. I just want to highlight arbitrarily-shaped image just as Finder does with icons.

Try NSCompositeSourceAtop with black at 50% alpha.

Andrew
__________________________________________________________________
A n d r e w P l a t z e r
A p p l i c a t i o n F r a m e w o r k s
A p p l e
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.


  • Follow-Ups:
    • Re: How to highlight an image with transparency [SOLUTION]
      • From: Andrew Platzer <email@hidden>
References: 
 >Re: How to highlight an image with transparency (From: Andrew Platzer <email@hidden>)

  • Prev by Date: Re: kCFCompareNumerically
  • Next by Date: Re: NSWorkspaceDidTerminateApplicationNotification bug?
  • Previous by thread: Re: How to highlight an image with transparency
  • Next by thread: Re: How to highlight an image with transparency [SOLUTION]
  • Index(es):
    • Date
    • Thread