473,387 Members | 1,864 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

GDI (-) & Translucent brush

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!
Nov 17 '05 #1
7 3298
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.

"Lloyd Dupont" <net.galador@ld> wrote in message
news:ON**************@TK2MSFTNGP14.phx.gbl...
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!

Nov 17 '05 #2
hu.....
thanks for your tips!

"Michael Phillips, Jr." <mp*********@nospam.jun0.c0m> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...
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.

"Lloyd Dupont" <net.galador@ld> wrote in message
news:ON**************@TK2MSFTNGP14.phx.gbl...
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!


Nov 17 '05 #3
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...

"Michael Phillips, Jr." <mp*********@nospam.jun0.c0m> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...
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.

"Lloyd Dupont" <net.galador@ld> wrote in message
news:ON**************@TK2MSFTNGP14.phx.gbl...
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!


Nov 17 '05 #4
> 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.
Nov 17 '05 #5
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
"Michael Phillips, Jr." <mp*********@nospam.jun0.c0m> wrote in message
news:%2******************@TK2MSFTNGP12.phx.gbl...
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.

Nov 17 '05 #6
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.
"Lloyd Dupont" <net.galador@ld> wrote in message
news:Ot****************@TK2MSFTNGP09.phx.gbl...
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
"Michael Phillips, Jr." <mp*********@nospam.jun0.c0m> wrote in message
news:%2******************@TK2MSFTNGP12.phx.gbl...
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.


Nov 17 '05 #7
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.

"Michael Phillips, Jr." <mp*********@nospam.jun0.c0m> wrote in message
news:%2******************@TK2MSFTNGP09.phx.gbl...
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.
"Lloyd Dupont" <net.galador@ld> wrote in message
news:Ot****************@TK2MSFTNGP09.phx.gbl...
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
"Michael Phillips, Jr." <mp*********@nospam.jun0.c0m> wrote in message
news:%2******************@TK2MSFTNGP12.phx.gbl...
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.



Nov 17 '05 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Rene | last post by:
I would like to get a reference to a Brush using the color name of the brush. For example, right now if I want a brush with a certain color, I would hard code something like Brushes.PeachPuff, this...
2
by: boxim | last post by:
having a moment, cant you just Brush br = new Brush(Color.Black);??? saying you cant cos it's an abstract class need to get to a brush from a color tia sam martin
0
by: Rudolph Araujo | last post by:
Hi, I needed to build a data grid in which the first column has hyperlinks rather than simple text. I found the following code on this newsgroup and it works fine except for one problem. When I...
5
by: Dennis | last post by:
When I instantiate a Brush resource such as a solidbrush, do I need to dispose the resource when I'm finished or will it automatically be disposed when the function/sub it's used in ends? Thank...
0
by: UJ | last post by:
I have a WinForm program that has stuff on the form. I want to add something to it that will have an image over a portion of the window that is translucent. How can I do this? Also - I need to...
8
by: Lou | last post by:
I have a picture box with an image loaded into it from an Image list (Its a solid Black Image). Next I draw some lines into the picture box. The resulting image with the lines is NOT the return...
0
by: tristanlbailey | last post by:
I have been attempting to solve this problem for a few weeks now, but I'm not having much luck... I would like to create a seamless fading effect on each form/window in my program; one that, when...
2
by: Johnny J. | last post by:
I've got an inherited control where I want the user to be able to specify a color property. Using that color, I'm drawing a line private m_UserDefinedColor as Color ..... Dim g as...
31
by: Tom P. | last post by:
I am doing quite a bit of custom painting and it means I have to create a lot of brushes (think one for every file system object in a directory) per paint. How expensive is this? Should I find a...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.