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...