Re: Wierd problem when alpha blitting image with text in it



Layered windows support per-pixel and source constant alphas simultaneously.
In fact, I use that very thing in my project to fade
out alpha-blended drop shadows. The shadow itself is built of 4 rows of
per-pixel alpha blended bitmap. When the shadow is faded out, the source
constant alpha is applied to the whole window.

To draw the image at the link you supplied, you would need to initialize the
"internal" parts (not the translucent frame portion) of the window to have
an alpha of 0xff or it will never work correctly when painted to the layered
window.

I'm not sure how that window is being painted code wise, but I would have
the background (the white area and the translucent rounded frame and purple
area) loaded as a 32bit DIB preserving the alphas. The inside white area
would then have 0xff alphas by design. Then paint on top of that. But you
need to use that "HBITMAP" as your base and not something thats the result
of CreateCompatibleBitmap().

To do my alpha-blended drop shadow, I drew the drop shadow in Photoshop,
saved it as a PSD, and then converted that PSD to a 32-bit DIB using Gif
MovieGear.

Code wise, I create a 32bit DIB which is initialized to all 0x00. Which is
appropriate for a drop shadow because everything except the drop shadow
needs to be transparent. I load each portion of the drop shadow bitmap as a
32bit DIB and BitBlt to the memory DC that holds the 32bit DIB. That'll
preserve the alphas in that case. Finally, I call UpdateLayeredWindow() to
have the OS paint to the layered window.

P.S. Nice UI, except the drop shadow is on the wrong side :). The "sun"
comes from the upper left, so the shadow should be on the lower right, not
the lower left.


"Dean Roddey" <droddey@xxxxxxxxxxxxxxxx> wrote in message
news:OLEPAc3sGHA.4992@xxxxxxxxxxxxxxxxxxxxxxx
That's not really possible. I have to initialize it to fully transparent,
because this is a secondary bitmap that is being drawn into and which will
then be composited over the other (fully opaque) bitmap. So clearly
everything not explicitly drawn into must have a zero alpha channel
because you don't want it to show up when you composite the secondary
drawn content over the base image.

If all the drawning APIs effectively set the alpha to zero, then it would
be impossible to composite two such images, and I'm starting to think that
this is the case (and the reason why LayeredWindows don't support both
constant opacity and alpha channel at the same time, becaues Window's just
has too limited support for alpha channel.)

The reason we want to draw into the secondary image and then composite it
is so that we can apply a constant opacity to the subsequent layers, i.e.
draw the second images into an intially zeroed alpha channel to create a
correctly alpha channelled secondary image, and then do an alpha blit from
the secondary image over the primary image, possibly applying constant
opacity as we go.

But if all the drawing APIs zero the alpha channel, then it would require
that all compositing be done by drawing into a single memory image, which
prevents the application of constant opacity. Oh well, I guess I'll just
have to give up on that and just draw into the single memory image. At
least I can get correct alpha channel support that way.

Here's a better example of the kind of thing it's being used for:

http://www.charmedquark.com/Web2/Downloads/MiscImages/V17Previews/PopupExp8.jpg

I'm poppinp up a CD selection 'popup'. We'd really like those types of
popups to be slighly to quite translucent overall by applying teh constant
opacity to it. In a case like this one, the alpha channel in the
background image of the popup is sufficient to provide the required
effect. But for an 'on screen display' type of popup, it really needs to
be able to draw text and composite over the background with constant
opacity.

-------------------------------------
Dean Roddey
Chairman/CTO, Charmed Quark Systems
www.charmedquark.com

"Nobody" <nobody@xxxxxxx> wrote in message
news:jBOyg.132$0F5.74@xxxxxxxxxxxxx
"Dean Roddey" <droddey@xxxxxxxxxxxxxxxx> wrote in message
news:epclHYusGHA.1216@xxxxxxxxxxxxxxxxxxxxxxx

All the Windows APIs that draw to bitmaps (text, line, etc) leave you
with an alpha channel of 0x00 (except those APIs which specifically
manipulate the alpha channel). An alpha of 0x00 is fully transparent. You
need to initialize your memory DC to have alphas of 0xff and then layer
it up from there.





.



Relevant Pages

  • Re: Wierd problem when alpha blitting image with text in it
    ... When the shadow is faded out, ... constant alpha is applied to the whole window. ... windows can have per-pixel but cannot have any child windows. ... So this leaves me with the image pixels being however opaque they ...
    (microsoft.public.win32.programmer.gdi)
  • long, boring explanation of minicopy (and HBVS, in general)
    ... > be a general consensus about what works, what is the proper behaviour, ... writes registered on a minicopy bitmap that exists on an Alpha (or Itanium, ... as long as the shadow set is mounted on an Alpha (even if its connection ...
    (comp.os.vms)
  • Re: two questions about MINICOPY
    ... >> connection to the shadow set fails), can I expect that a) a minicopy ... > shadow server knows nothing about files. ... >> mounting it from an ALPHA after all, ...
    (comp.os.vms)
  • Re: CPC TREX 24MHz Turbo Core available PLUS complete source code!
    ... I don't know, which alpha version do you have, but there are two new ... the "shadow" system runs fast again. ... the starter SymbOS is included in the flash file, ...
    (comp.sys.amstrad.8bit)
  • Re: Configuring GVIM
    ... you do these commands in command mode, ... 200/255 alpha ... Maximized Window: ... Put "messageforohmster" in message body ...
    (comp.editors)

Loading