Getting transparent bitmap

DLL Edition of the F-IN-BOX
Zeratul
Posts: 24
Joined: Sat Apr 01, 2006 8:19 am

Getting transparent bitmap

Postby Zeratul » Sat Apr 01, 2006 8:22 am

Is it possible to get bitmap image with transparency channel(RGBA 32 bits)?
If so how? In Direct3D demo bitmap for texture returned with black background.

Softanics
Site Admin
Posts: 1402
Joined: Sat Sep 18, 2004 3:03 am
Location: Russia, St. Petersburg
Contact:

Re: Getting transparent bitmap

Postby Softanics » Sat Apr 01, 2006 1:32 pm

Thank you for your question.

Zeratul wrote:Is it possible to get bitmap image with transparency channel(RGBA 32 bits)? If so how?


Yes, it's possible.

Zeratul wrote:In Direct3D demo bitmap for texture returned with black background.


You are right, but in this example bitmaps are really have transparency channel. See a buffer of pixels in the debugger.
Best regards, Artem A. Razin,
F-IN-BOX support
Ask your question here: http://www.f-in-box.com/support.html

amit
Posts: 5
Joined: Mon Mar 27, 2006 3:20 pm

Postby amit » Mon Apr 17, 2006 7:46 pm

Hello,

I am trying to get a bitmap with alpha channel from the frame, but all I get is a bitmap with black background.

My code looks like this:

I define the flash window:

Code: Select all

   // Create FlashPlayerControl as a hidden child control
   // in transparent mode (see style FPCS_TRANSPARENT)
   g_hwndFlashPlayerControl =
      CreateWindowEx(WS_EX_LAYERED,
                    WC_FLASH,
                    NULL,
                    WS_POPUP | WS_VISIBLE,
                    0,
                    0,
                    320,
                    240,
                    g_hDlg,
                    NULL,
                    NULL,
                    NULL);



And I get the bitmap using:

Code: Select all

   MoveWindow(g_hwndFlashPlayerControl, 0, 0, m_mode->width, m_mode->height, TRUE);

   SFPCGetFrameBitmap FPCGetFrameBitmap = { 0 };
   ::SendMessage(g_hwndFlashPlayerControl, FPCM_GET_FRAME_BITMAP, 0, (LPARAM)&FPCGetFrameBitmap);

   HBITMAP pwebcam_HBITMAP = FPCGetFrameBitmap.hBitmap;

    HPALETTE hpal = (HPALETTE) GetStockObject(DEFAULT_PALETTE);
    Bitmap* pflash_bitmap = Bitmap::FromHBITMAP(pwebcam_HBITMAP, hpal);


The movie is displayed in a transparent window (I use WS_VISIBLE so I can see the flash window) but the bitmap I get has black background.

What am I doing wrong?

Thanks in advance,
Amit

Softanics
Site Admin
Posts: 1402
Joined: Sat Sep 18, 2004 3:03 am
Location: Russia, St. Petersburg
Contact:

Postby Softanics » Tue Apr 18, 2006 8:36 am

amit wrote:The movie is displayed in a transparent window (I use WS_VISIBLE so I can see the flash window) but the bitmap I get has black background.


These black pixels are fully transparent pixels. You can change color of such pixels:

Code: Select all

   SFPCGetFrameBitmap FPCGetFrameBitmap = { 0 };
   ::SendMessage(m_hwndFlashPlayerControl, FPCM_GET_FRAME_BITMAP, 0, (LPARAM)&FPCGetFrameBitmap);
   HBITMAP hBitmap = FPCGetFrameBitmap.hBitmap;

   BITMAP bmp_info;
   GetObject(hBitmap, sizeof(bmp_info), &bmp_info);

   DWORD* pBitmapBits = (DWORD*)bmp_info.bmBits;

   const DWORD dwNewColor = 0x00ff0000;

   for (int j = 0; j < bmp_info.bmHeight; j++)
      for (int i = 0; i < bmp_info.bmWidth; i++)
      {
         DWORD dwPixelColor = *pBitmapBits;

         // dwPixelColor = 0xAARRGGBB
         if ( 0 == ( dwPixelColor & 0xff000000 ) )
         {
            dwPixelColor = (dwPixelColor & 0xff000000) | dwNewColor;
            *pBitmapBits = dwPixelColor;
         }

         pBitmapBits++;
      }

   // For testing
   CImage Image;
   Image.Attach(hBitmap);
   Image.Save(_T("1.bmp"));
   Image.Detach();
Best regards, Artem A. Razin,

F-IN-BOX support

Ask your question here: http://www.f-in-box.com/support.html

amit
Posts: 5
Joined: Mon Mar 27, 2006 3:20 pm

Postby amit » Tue Apr 18, 2006 3:52 pm

Hello,

I modified my code according to your explanation and it works great.

I attach my test code, in case somebody might be interested. In this example I am creating a GDI+ bitmap from the flash BITMAP buffer and I draw it on another bitmap.

Code: Select all

   SFPCGetFrameBitmap FPCGetFrameBitmap = { 0 };
   ::SendMessage(g_hwndFlashPlayerControl, FPCM_GET_FRAME_BITMAP, 0, (LPARAM)&FPCGetFrameBitmap);

   HBITMAP pflash_HBITMAP = FPCGetFrameBitmap.hBitmap;

    BITMAP flash_BITMAP;
    GetObject(pflash_HBITMAP, sizeof(flash_BITMAP), &flash_BITMAP);

    BYTE* pflash_buffer = (BYTE*)flash_BITMAP.bmBits;
    pflash_buffer = pflash_buffer + flash_BITMAP.bmWidth * (flash_BITMAP.bmHeight - 1) * NUM_RGBA_CHANNELS;
    INT stride = - (INT)flash_BITMAP.bmWidth * NUM_RGBA_CHANNELS;

    Bitmap* pflash_bitmap = new Bitmap(
                                (INT)flash_BITMAP.bmWidth,
                                (INT)flash_BITMAP.bmHeight,
                                stride,
                                PixelFormat32bppPARGB,
                                pflash_buffer
                                );

...

    Graphics graphics(panother_bitmap);
    graphics.SetCompositingMode(CompositingModeSourceOver);

    Status status = graphics.DrawImage(
                pflash_bitmap,
                0,
                0
                );
   


Thanks,
Amit


Return to “DLL Edition”

Who is online

Users browsing this forum: No registered users and 13 guests

cron