GDI (-) & Translucent brush

  • Thread starter Thread starter Lloyd Dupont
  • Start date Start date
L

Lloyd Dupont

In my C# & MC++ app there is some drawing done through GDI (not +, but
win32).
I would like to be able to create a translucent HBRUSH.

the RGB macro create only solid color...
and, anyway, CreateSolidBrush ignore the higher byte.

Any idea?

I though I might do some trick with CreateDIBPatternBrush but I'm not sure
on what to do...

Any tips wellcome!
 
You are on the right track!

1)You could create an alpha channel DIB and select it into
a device context (i.e., use BITMAPV5HEADER).

2)Create your brushes and draw them to the device backed by
the DIB.

3) Using the bits, change the alpha byte to the level of
translucency that you desire.

4) Premultiply the alpha channel against the RGB values.

5) Use the AlphaBlend function to draw your translucent brush.
 
hu.....
thanks for your tips!

Michael Phillips said:
You are on the right track!

1)You could create an alpha channel DIB and select it into
a device context (i.e., use BITMAPV5HEADER).

2)Create your brushes and draw them to the device backed by
the DIB.

3) Using the bits, change the alpha byte to the level of
translucency that you desire.

4) Premultiply the alpha channel against the RGB values.

5) Use the AlphaBlend function to draw your translucent brush.
 
mmhh.. well..
There are some problem with this approch.
I created a 1x1 pixel bitmap of the right color, get its HBITMAP< select it
in a memory, screen compatible, DC and AlphaBlend it.

But translucent color get a blue tint.
In fact worst than that, they get a blue tint.. most of the time (but not
always).

Fiu..
I think I will forgot about translucent painting in GDI...
 
There are some problem with this approach.
I created a 1x1 pixel bitmap of the right color, get its HBITMAP< select
it in a memory, screen compatible, DC and AlphaBlend it.

Could you be more specific. Did you follow my steps and
premultiply the alpha channel?

If you don't create and use the bitmap correctly with the
AlphaBlend function, you will get a blue tint.

If you use BitBlt, you will see the blue tinted background.
When you use AlphaBlend correctly with premultiplied
alpha channel, you will not see a blue tint.

There is another approach. You can define a mask to
represent the translucency and use MaskBlt.

You will not be able to define an opacity in the range of 0 -100%
with the MaskBlt approach.
 
ok, I will be at work in 2 hours.
could gives me more detail?

what do you mean by:

4) Premultiply the alpha channel against the RGB values.

I created the bitmap in 2 ways.
SD.Bitmap.GetHBitmap()
or as in the code sample in AlphaBlend documentation with CreateDibBitmpa(),
using a BITMAPHEADER (and not a BITMAPV5HEADER)

in the BLENDFUNCTION I used opaque value: 0xff.

could you give me some more tips?

and thanks for your tips so far ;-)


if I set the
 
You usually premultiply the alpha channel against the RGB colors
when you use AlphaBlend with SourceConstantAlpha = 0xFF.

However the technique that I outlined does not work. I tried creating both
solid and hatch DIB pattern brushes but GDI still ignores the
alpha channel whether I premultiply or set different opacity
levels in the range 0 - 1. I guess you have to roll your own
FillRect or Rectangle function to accept alpha channel brushes.

I believe that GIMP can create translucent brushes.
You may want to download the code to see how they
accomplish the effect.
 
Thanks Michael!
Anyway translucent GDI brush is not that essential at this stage. So I just
dropped it.
I'm just a bit frustrated, that's all.
 
Back
Top