locked
How to show a second picture on SwapchainbackgroundPanel via Alpha channel

    Question

  • Hi,

      I have to render the second picture over the first rendered picture, But I don.t know how to implement the effect. The swapchain's pixel format is DXGI_FORMAT_R8B8G8A8_UNORM;

    The pixel format for the two pictures and target bitmap is (DXGI_FORMAT_R8B8G8A8_UNORM, D2D1_ALPHA_MODE_PREMULTIPLITED).

    Here is the basic logic in my code :

        =>Create targetBitmap with the same pixel format, d2d1Context->setTarget() //             set it as the target

        => Create bitmap1和bitmap2  

    when display:

         // First draw the first bitmap

          bitmap1->CopyFromMemory();

          md2dContext->DrawImage(bitmap1->Get(), (0,0), rc,                  D2D1_INTERPOLATION_MODE_LINER,      D2D1_COMPOSITE_MODE_BOUNDED_SOURCE_COPY);

    // Then draw the second bitmap

    // Here I tried to set all the data to 0XFF00FF00 and 0X0000FF00, but they all show    pure green, which means the alpha is ignored.

             buffer[] = {0X000FF00..};  

            bitmap2->CopyFromMemory(buffer...);

            md2dContext->DrawImage(bitmap2->Get(), (0,0), rc,    D2D1_INTERPOLATION_MODE_LINER, D2D1_COMPOSITE_MODE_PLUS);

           md2dContext->EndDraw();

    Is the composite mode for the second picture is wrong ?

    should I manually combine the two picture based on the value of alpha ? That means calculate each pixel ...... 

    Thank you !

    Dong


    • Edited by wd0623 Thursday, October 24, 2013 3:40 AM edit
    Thursday, October 24, 2013 3:37 AM

All replies

  • Hi Dong,

    Take a look at the Direct2D composite effect modes sample for samples of how to composite two images in various ways.

    --Rob

    Friday, October 25, 2013 1:20 AM
    Owner
  • Hi Dong,

    Take a look at the Direct2D composite effect modes sample for samples of how to composite two images in various ways.

    --Rob

    Thanks, Rob. If the two pictures in different size, how to deal with that ?  I notice the demo and the msdn

    doc are all using two pictures in same size.  I have to combine a small picture into a larger one.  Thank you very much!

    Dong.

    Wednesday, October 30, 2013 3:47 AM