NSImage drawAtPoint & Transparency

  • Hello everyone

    I've encountered an odd little problem.  In my view's drawRect method
    I'm drawing an NSImage to the screen.  The image has transparency
    (which I can verify by viewing it in Photoshop, and by double-clicking
    on it in XCode and seeing it's transparent parts when XCode shows me
    the image.)

    But, when I draw it to the screen, it has a black background instead
    of transparent.  I'm using the following code:

    [currentImage drawAtPoint: NSMakePoint(0,-2) fromRect: NSZeroRect
    operation: NSCompositeCopy fraction: 1.0];

    Does anyone have an idea what may be making it draw a black
    background?  I've even tried [currentImage setBackgroundColor:
    [NSColor clearColor]]; without luck.

    Thank you
    AA
  • On Oct 15, 2006, at 12:46 PM, Aychamo Aychamo wrote:
    > [currentImage drawAtPoint: NSMakePoint(0,-2) fromRect: NSZeroRect
    > operation: NSCompositeCopy fraction: 1.0];
    >
    > Does anyone have an idea what may be making it draw a black
    > background?  I've even tried [currentImage setBackgroundColor:
    > [NSColor clearColor]]; without luck.

      Try NSCompositeSourceOver instead.

    --
    I.S.
  • Ahh, that worked.  I looked in the docs beforehand at the different
    NSComposite constants, but when trying to figure out what they did, it
    seemed cryptic.  Now that I see that that one works, it makes more
    sense.

    As always, thank you
    AA

    On 10/15/06, I. Savant <idiotsavant2005...> wrote:
    > On Oct 15, 2006, at 12:46 PM, Aychamo Aychamo wrote:
    >> [currentImage drawAtPoint: NSMakePoint(0,-2) fromRect: NSZeroRect
    >> operation: NSCompositeCopy fraction: 1.0];
    >>
    >> Does anyone have an idea what may be making it draw a black
    >> background?  I've even tried [currentImage setBackgroundColor:
    >> [NSColor clearColor]]; without luck.
    >
    >
    > Try NSCompositeSourceOver instead.
    >
    > --
    > I.S.
    >
    >
    >
    >
  • Am 15.10.2006 um 19:10 schrieb Aychamo Aychamo:
    > Ahh, that worked.  I looked in the docs beforehand at the different
    > NSComposite constants, but when trying to figure out what they did, it
    > seemed cryptic.  Now that I see that that one works, it makes more
    > sense.

    I had the same problem once, and created a little image with all the
    different operations at:

    http://www.zathras.de/angelweb/blog-nscompositingoperation-at-a-
    glance.htm

    The trouble is that my server is having problems right now, so it may
    be a while until you can see it again :-(

    Cheers,
    -- M. Uli Kusterer
    http://www.zathras.de
  • Hi,

      my site is sort-of back up now. I'm still trying to get the
    remaining things sorted out, but the page

    http://www.zathras.de/angelweb/blog-nscompositingoperation-at-a-
    glance.htm

    with the a nice picture showing all the different compositing
    operations should be available again.

    Cheers,
    -- M. Uli Kusterer
    http://www.zathras.de
  • There is a similar depiction of the compositing modes in "Cocoa Programming" starting on page 522.

      The example program, CompositeLab, can be found in /Developer/examples/AppKit/CompositeLab
  • On or about 10/19/06 10:58 PM, thus spake
    "<cocoa-dev-request...>" <cocoa-dev-request...>:

    > Date: Thu, 19 Oct 2006 22:37:15 +0200
    > From: Uli Kusterer <witness.of.teachtext...>
    > Subject: Re: NSImage drawAtPoint & Transparency
    > Am 15.10.2006 um 19:10 schrieb Aychamo Aychamo:
    >> Ahh, that worked.  I looked in the docs beforehand at the different
    >> NSComposite constants, but when trying to figure out what they did, it
    >> seemed cryptic.  Now that I see that that one works, it makes more
    >> sense.
    >
    > I had the same problem once, and created a little image with all the
    > different operations at:
    >
    > http://www.zathras.de/angelweb/blog-nscompositingoperation-at-a-
    > glance.htm

    I really find the CompositeLab example (already on your hard disk) most
    helpful, actually. m.

    --
    matt neuburg, phd = <matt...>, http://www.tidbits.com/matt/
    pantes anthropoi tou eidenai oregontai phusei
    AppleScript: the Definitive Guide - Second Edition!
    http://www.amazon.com/gp/product/0596102119
    Take Control of Word 2004, Tiger, and more -
    http://www.takecontrolbooks.com/tiger-customizing.html
    Subscribe to TidBITS! It's free and smart. http://www.tidbits.com/
previous month october 2006 next month
MTWTFSS
            1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31          
Go to today