How to highlight an image with transparency [SOLUTION]
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.