GDI (-) & Translucent brush

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Lloyd Dupont

    #1

    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, CreateSolidBrus h ignore the higher byte.

    Any idea?

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

    Any tips wellcome!


  • Michael Phillips, Jr.

    #2
    Re: GDI (-) & Translucent brush

    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:ONXbs9O6FH A.3120@TK2MSFTN GP14.phx.gbl...[color=blue]
    > 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, CreateSolidBrus h ignore the higher byte.
    >
    > Any idea?
    >
    > I though I might do some trick with CreateDIBPatter nBrush but I'm not sure
    > on what to do...
    >
    > Any tips wellcome!
    >[/color]


    Comment

    • Lloyd Dupont

      #3
      Re: GDI (-) &amp; Translucent brush

      hu.....
      thanks for your tips!

      "Michael Phillips, Jr." <mphillips53@no spam.jun0.c0m> wrote in message
      news:%23qfR6LS6 FHA.1420@TK2MSF TNGP09.phx.gbl. ..[color=blue]
      > 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:ONXbs9O6FH A.3120@TK2MSFTN GP14.phx.gbl...[color=green]
      >> 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, CreateSolidBrus h ignore the higher byte.
      >>
      >> Any idea?
      >>
      >> I though I might do some trick with CreateDIBPatter nBrush but I'm not
      >> sure on what to do...
      >>
      >> Any tips wellcome!
      >>[/color]
      >
      >[/color]


      Comment

      • Lloyd Dupont

        #4
        Re: GDI (-) &amp; 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...

        "Michael Phillips, Jr." <mphillips53@no spam.jun0.c0m> wrote in message
        news:%23qfR6LS6 FHA.1420@TK2MSF TNGP09.phx.gbl. ..[color=blue]
        > 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:ONXbs9O6FH A.3120@TK2MSFTN GP14.phx.gbl...[color=green]
        >> 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, CreateSolidBrus h ignore the higher byte.
        >>
        >> Any idea?
        >>
        >> I though I might do some trick with CreateDIBPatter nBrush but I'm not
        >> sure on what to do...
        >>
        >> Any tips wellcome!
        >>[/color]
        >
        >[/color]


        Comment

        • Michael Phillips, Jr.

          #5
          Re: GDI (-) &amp; Translucent brush

          > There are some problem with this approach.[color=blue]
          > I created a 1x1 pixel bitmap of the right color, get its HBITMAP< select
          > it in a memory, screen compatible, DC and AlphaBlend it.[/color]

          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.


          Comment

          • Lloyd Dupont

            #6
            Re: GDI (-) &amp; Translucent brush

            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.GetHB itmap()
            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@no spam.jun0.c0m> wrote in message
            news:%23gyi%23A f6FHA.3592@TK2M SFTNGP12.phx.gb l...[color=blue][color=green]
            >> 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.[/color]
            >
            > 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.
            >[/color]


            Comment

            • Michael Phillips, Jr.

              #7
              Re: GDI (-) &amp; Translucent brush

              You usually premultiply the alpha channel against the RGB colors
              when you use AlphaBlend with SourceConstantA lpha = 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%23i6 FHA.1420@TK2MSF TNGP09.phx.gbl. ..[color=blue]
              > 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.GetHB itmap()
              > 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@no spam.jun0.c0m> wrote in message
              > news:%23gyi%23A f6FHA.3592@TK2M SFTNGP12.phx.gb l...[color=green][color=darkred]
              >>> 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.[/color]
              >>
              >> 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.
              >>[/color]
              >
              >[/color]


              Comment

              • Lloyd Dupont

                #8
                Re: GDI (-) &amp; Translucent brush

                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." <mphillips53@no spam.jun0.c0m> wrote in message
                news:%23eUx%23u j6FHA.1420@TK2M SFTNGP09.phx.gb l...[color=blue]
                > You usually premultiply the alpha channel against the RGB colors
                > when you use AlphaBlend with SourceConstantA lpha = 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%23i6 FHA.1420@TK2MSF TNGP09.phx.gbl. ..[color=green]
                >> 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.GetHB itmap()
                >> 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@no spam.jun0.c0m> wrote in message
                >> news:%23gyi%23A f6FHA.3592@TK2M SFTNGP12.phx.gb l...[color=darkred]
                >>>> 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.
                >>>[/color]
                >>
                >>[/color]
                >
                >[/color]


                Comment

                Working...