all groups > visual c > november 2005 >
visual c :
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!
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. [quoted text, click to view] "Lloyd Dupont" <net.galador@ld> wrote in message news:ONXbs9O6FHA.3120@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! >
hu..... thanks for your tips! [quoted text, click to view] "Michael Phillips, Jr." <mphillips53@nospam.jun0.c0m> wrote in message news:%23qfR6LS6FHA.1420@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:ONXbs9O6FHA.3120@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! >> > >
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... [quoted text, click to view] "Michael Phillips, Jr." <mphillips53@nospam.jun0.c0m> wrote in message news:%23qfR6LS6FHA.1420@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:ONXbs9O6FHA.3120@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! >> > >
[quoted text, click to view] > 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.
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. [quoted text, click to view] "Lloyd Dupont" <net.galador@ld> wrote in message news:OteAh%23i6FHA.1420@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." <mphillips53@nospam.jun0.c0m> wrote in message > news:%23gyi%23Af6FHA.3592@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. >> > >
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. [quoted text, click to view] "Michael Phillips, Jr." <mphillips53@nospam.jun0.c0m> wrote in message news:%23eUx%23uj6FHA.1420@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:OteAh%23i6FHA.1420@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." <mphillips53@nospam.jun0.c0m> wrote in message >> news:%23gyi%23Af6FHA.3592@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. >>> >> >> > >
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 [quoted text, click to view] "Michael Phillips, Jr." <mphillips53@nospam.jun0.c0m> wrote in message news:%23gyi%23Af6FHA.3592@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. >
Don't see what you're looking for? Try a search.
|
|
|