Qt, QPixmap, VMR9 et Overlay Video

cs_fenrhyr Messages postés 15 Date d'inscription jeudi 23 septembre 2004 Statut Membre Dernière intervention 5 avril 2005 - 1 déc. 2004 à 11:10
cs_fenrhyr Messages postés 15 Date d'inscription jeudi 23 septembre 2004 Statut Membre Dernière intervention 5 avril 2005 - 1 déc. 2004 à 15:08
Bonjour

J'utilise Qt3, windowsXP et j'essaie de mettre un QPixmap en overlay sur une live video.

J'ai la video, je peux faire un overlay d'un bitmap avec la fonction LoadImage() mais je ne peux pas le faire avec un Qpixmap que je passe en bitmap, il faut pourtant que je le fasse ainsi puisque je travaille sur le qpixmap avant de l'afficher

Du code vaut peut-etre mieux qu'une longue histoire

BOOL QVMRWidget::SetBitmap(/*HDC hdc,*/ int nAlpha, COLORREF cTransColor, RECT
bitmapRect)
{

LONG cx, cy;
HRESULT hr;
hr = m_pVMRWindowlessControl->GetNativeVideoSize(&cx, &cy, NULL, NULL);
if (FAILED(hr))
{
ReportError("GetNativeVideoSize FAILED! Bitmap operations will fail",
hr);
return FALSE;
}
QPixmap :: setDefaultOptimization(QPixmap :: DefaultOptim);
QPixmap pm("InterfaceBackground1.bmp");


HBITMAP hbm = (HBITMAP)pm.hbm();
//HBITMAP hbm = (HBITMAP)LoadImage(NULL, L"InterfaceBackground1.bmp",
IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE|LR_CREATEDIBSECTION); //This is working
well !

qDebug("hbm = %x", hbm);


HDC hdc = GetDC(m_hMediaWindow);
if (hdc == NULL)
{
return E_FAIL;
}

HDC hdcBmp = CreateCompatibleDC(hdc);
ReleaseDC(m_hMediaWindow, hdc);

if (hdcBmp == NULL)
{
qDebug("hdcBmp == NULL");
return E_FAIL;
}

BITMAP bm;
if (0 == GetObject(hbm, sizeof(bm), &bm))//(hNewBitmap, sizeof(bm), &bm))
{
qDebug("GetObject is NULL");
DeleteDC(hdcBmp);
return E_FAIL;
}

HBITMAP hbmOld = (HBITMAP)SelectObject(hdcBmp,hbm);

if (hbmOld == 0)
{
DeleteDC(hdcBmp);
qDebug("hbmOld FAILED");
return E_FAIL;
}

VMR9NormalizedRect nRect = NormalizeRect(&bitmapRect);
VMR9AlphaBitmap bmpInfo;
ZeroMemory(&bmpInfo, sizeof(bmpInfo) );
bmpInfo.dwFlags = VMR9AlphaBitmap_hDC | VMR9AlphaBitmap_SrcColorKey;
bmpInfo.hdc = hdcBmp;

// Show the entire bitmap in the top-left corner of the video image.
SetRect(&bmpInfo.rSrc, 0, 0, 300, 300); //bm.bmWidth, bm.bmHeight);

bmpInfo.rDest.top = nRect.top;
bmpInfo.rDest.left = nRect.left;
bmpInfo.rDest.bottom = nRect.bottom;
bmpInfo.rDest.right = nRect.right;

// Set the transparency value (1.0 is opaque, 0.0 is transparent).
bmpInfo.fAlpha = nAlpha / 100.0f;

// set colorkey value
bmpInfo.clrSrcKey = cTransColor;

hr = m_pVMRMixerBitmap->SetAlphaBitmap(&bmpInfo);
if (FAILED(hr))
ReportError("SetAlphaBitmap FAILED! Bitmap operations will fail",
hr);

DeleteObject(SelectObject(hdcBmp, hbmOld));
DeleteDC(hdcBmp);

return TRUE;

}

La debug window me sort:
hbm = 13050eee
hbmOld FAILED
Pourquoi la fonction SelectObject() echoue a l'appel avec hbm pm.hbm() et non avec hbm LoadImage() ??? Que puis-je faire ??

Please, help...

1 réponse

cs_fenrhyr Messages postés 15 Date d'inscription jeudi 23 septembre 2004 Statut Membre Dernière intervention 5 avril 2005
1 déc. 2004 à 15:08
Juste pour dire que c'est une fois le message poste que l'on trouve la solution ^^

Pour ceux que ca interesse, il convient de faire :

HDC hBmpDC1 = CreateCompatibleDC(hdc);
HBITMAP hNewBitmap = CreateCompatibleBitmap(hdc, pm.width(), pm.height());
HBITMAP hOldBmpDC1 = (HBITMAP) SelectObject(hBmpDC1, hNewBitmap);
if (hOldBmpDC1 == 0)
{
DeleteDC(hBmpDC1);
qDebug("hOldBmpDC1 FAILED");
return E_FAIL;
}

StretchBlt(hBmpDC1, 0, 0, pm.width(), pm.height(), pm.handle()/*hBmpDC2*/, 0, 0,pm.width(), pm.height(), SRCCOPY);
0
Rejoignez-nous