IVMRMixerBitmap and GDI+ bitmap

IVMRMixerBitmap and GDI+ bitmap

Post by Pascal Clo » Thu, 02 Mar 2006 00:43:46


This is a multi-part message in MIME format.


Hi,

i want to blend a Bitmap created with C#/.net framework with a movie using IVMRMixerBitmap.
So the problem is how to convert GDI+ Bitmap object to the HDC required in a field of VMRALPHABITMAP .

Someone can help?

thanks in advance,
Pascal
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=Content-Type content="text/html; charset=iso-8859-1">
<META content="MSHTML 6.00.2900.2802" name=GENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY>
<DIV><FONT face=Arial size=2>Hi,</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT> </DIV>
<DIV><FONT face=Arial size=2>i want to blend a Bitmap created with C#/.net
framework with a movie using IVMRMixerBitmap.</FONT></DIV>
<DIV><FONT face=Arial size=2>So the problem is how to convert <FONT
size=2>G</FONT>DI+ Bitmap object to the HDC required in a field of <FONT
size=3><FONT face="Times New Roman"><STRONG>VMRALPHABITMAP</STRONG>
</FONT></FONT>.</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT> </DIV>
<DIV><FONT face=Arial size=2>Someone can help?</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT> </DIV>
<DIV><FONT face=Arial size=2>thanks in advance,</FONT></DIV>
<DIV><FONT face=Arial size=2>Pascal</FONT></DIV></BODY></HTML>
 
 
 

IVMRMixerBitmap and GDI+ bitmap

Post by Iain » Thu, 02 Mar 2006 03:08:48


GetHBitmap() ?

Iain
--
Iain Downs (DirectShow MVP)
Commercial Software Therapist
www.idcl.co.uk

 
 
 

IVMRMixerBitmap and GDI+ bitmap

Post by Pascal Clo » Thu, 02 Mar 2006 04:24:13

his is a multi-part message in MIME format.



"Iain" < XXXX@XXXXX.COM > a rit dans le message de news: skvhtr7o18o8.50nesumuu53p$ XXXX@XXXXX.COM ...

i tried this, doing something like:

Bitmap bm = new Bitmap(.....)
Graphics g = Graphics.FromImage( bm );

DrawMyDrawings( g );....

and call a function of my dll (written in Managed C++) which deals with Direct Show and IVMRMixerBitmap, and passing to it the arument you suggested:
bm.GetHbitmap()

but i get en error 0x80070057 (Invalid argument i think) when i call the method SetAlphaBitmap() of IVMRMixerBitmap.

Other suggestions?

thanks for help
Pascal

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=Content-Type content="text/html; charset=iso-8859-1">
<META content="MSHTML 6.00.2900.2802" name=GENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY>
<DIV><FONT face=Arial size=2></FONT> </DIV>
<DIV><FONT face=Arial size=2>"Iain" <</FONT><A
href="mailto: XXXX@XXXXX.COM "><FONT face=Arial
size=2> XXXX@XXXXX.COM </FONT></A><FONT face=Arial size=2>> a rit
dans le message de news: </FONT><A
href="mailto:skvhtr7o18o8.50nesumuu53p$ XXXX@XXXXX.COM "><FONT face=Arial
size=2>skvhtr7o18o8.50nesumuu53p$ XXXX@XXXXX.COM </FONT></A><FONT face=Arial
size=2>...</FONT></DIV>
<DIV><FONT face=Arial size=2>> On Tue, 28 Feb 2006 16:43:46 +0100, Pascal
Cloup wrote:<BR>> <BR>>> Hi,<BR>>> <BR>>> i want to blend a
Bitmap created with C#/.net framework with a movie using
IVMRMixerBitmap.<BR>>> So the problem is how to convert GDI+ Bitmap object
to the HDC required in a field of VMRALPHABITMAP .<BR>>> <BR>>>
Someone can help?<BR>>> <BR>>> thanks in advance,<BR>>>
Pascal<BR>> <BR>> GetHBitmap() ?</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT> </DIV>
<DIV><FONT face=Arial size=2>i tried this, doing something like:</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT> </DIV>
<DIV><FONT face=Arial size=2>Bitmap    bm = new
Bitmap(.....)</FONT></DIV>
<DIV><FONT face=Arial size=2>Graphics g = Graphics.FromImage( bm );</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT> </DIV>
<DIV><FONT face=Arial size=2>DrawMyDrawings( g );....</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT> </DIV>
<DIV><FONT face=Arial size=2>and call a function of my dll (written in Managed
C++)  which deals with Direct Show and IVMRMixerBitmap,  and
passing to it the arument you suggested:</FONT></DIV>
<DIV><FONT face=Arial size=2>bm.GetHbitmap()</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT> </DIV>
<DIV><FONT face=Arial size=2>but i get en error 0x80070057 (Invalid argument i
think) when i call the method <FONT size=2>SetAlphaBitmap()</FONT> of
IVMRMixerBitmap.</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT>
 
 
 

IVMRMixerBitmap and GDI+ bitmap

Post by Alessandro » Thu, 02 Mar 2006 06:19:59


From the IVMRMixerBitmap::SetAlphaBitmap() doc page:

<<<
E_INVALIDARG
Indicates a problem with the dwFlags member of the
VMRALPHABITMAP structure or failure to specify a valid HDC
or DirectDraw surface in the structure, or an invalid value
for fAlpha.

Are you sure all fields in VMRALPHABITMAP are correct?

--
// Alessandro Angeli
// MVP :: DirectShow / MediaFoundation
// a dot angeli at psynet dot net
 
 
 

IVMRMixerBitmap and GDI+ bitmap

Post by Iain » Thu, 02 Mar 2006 06:39:06


OK. What the function (the structure passed into it) is looking for is a
Device Context not a Bitmap Handle. So you want to retrieve the device
context from the Graphics object (g) not the bitmap handle from the
bitmap.

Iain
--
Iain Downs (DirectShow MVP)
Commercial Software Therapist
www.idcl.co.uk
 
 
 

IVMRMixerBitmap and GDI+ bitmap

Post by Pascal Clo » Thu, 02 Mar 2006 20:07:01

his is a multi-part message in MIME format.


Hello,
"Iain" < XXXX@XXXXX.COM > a rit dans le message de news: XXXX@XXXXX.COM ...

i found the origin of the error; in fact, i was set the flag VMRBITMAP_ENTIREDDS which specify entire surface, ... but DirectDraw surface.
So now, i call from C# my C++ function like this: player.PrepareToBlend( g.GetHdc() ) and there is no error.

But the result is always, a blend with a black bitmap ( but the bitmap, that's sure, contains some correct drawings)
my C++ code is:
int VideoPlayer::PrepareToBlend( IntPtr hdc , bool blend , int width , int height)

{

....

VMRALPHABITMAP vmrBitmap;

vmrBitmap.dwFlags = VMRBITMAP_HDC;

vmrBitmap.hdc = reinterpret_cast<HDC>( hdc.ToPointer() );

vmrBitmap.pDDS = NULL;

vmrBitmap.fAlpha = .5f;

vmrBitmap.rSrc.left = vmrBitmap.rSrc.top = 0;

vmrBitmap.rSrc.right = width; vmrBitmap.rSrc.bottom = height;

vmrBitmap.rDest.left = vmrBitmap.rDest.top = 0;

vmrBitmap.rDest.right = vmrBitmap.rDest.bottom = 1.0;



hr = pVMRMixerBitmap->SetAlphaBitmap( &vmrBitmap );

return( hr );
}


someone can help me?

thanks
Pascal

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=Content-Type content="text/html; charset=iso-8859-1">
<META content="MSHTML 6.00.2900.2802" name=GENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=#ffffff>
<DIV><FONT face=Arial size=2>Hello,</FONT></DIV>
<DIV><FONT face=Arial size=2>"Iain" <</FONT><A
href="mailto: XXXX@XXXXX.COM "><FONT face=Arial
size=2> XXXX@XXXXX.COM </FONT></A><FONT face=Arial size=2>> a rit
dans le message de news: </FONT><A
href="mailto: XXXX@XXXXX.COM "><FONT face=Arial
size=2> XXXX@XXXXX.COM </FONT></A><FONT face=Arial
size=2>...</FONT></DIV>
<DIV><FONT face=Arial size=2>> On Tue, 28 Feb 2006 20:24:13 +0100, Pascal
Cloup wrote:<BR>> <BR>>>> GetHBitmap() ?<BR>>> <BR>>> i
tried this, doing something like:<BR>>> <BR>>>
Bitmap    bm = new Bitmap(.....)<BR>>> Graphics g =
Graphics.FromImage( bm );<BR>>> <BR>>> DrawMyDrawings( g
);....<BR>>> <BR>>> and call a function of my dll (written in
Managed C++)  which deals with Direct Show and IVMRMixerBitmap,  and
passing to it the arument you suggested:<BR>>> bm.GetHbitmap()<BR>>>
<BR>> <BR>> OK.  What the function (the structure passed into it) is
looking for is a<BR>> Device Context not a Bitmap Handle.  So you want
to retrieve the device<BR>> context from the Graphics  object (g) not
the bitmap handle from the<BR>> bitmap.</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT> </DIV>
<DIV><FONT face=Arial size=2>i found the ori<FONT size=2>gin of the error; in
fact, i was set the flag VMRBITMAP_ENTIREDDS which specify entire surface, ...
but DirectDraw surface.</FONT></FONT></DIV>
<DIV><FONT face=Arial size=2>So now, i call from C#</FONT><FONT face=Arial
size=2> my C++ function like this: player.
 
 
 

IVMRMixerBitmap and GDI+ bitmap

Post by Iain » Thu, 02 Mar 2006 21:25:40


personally I just do a cast from the IntPtr value to the HDC - or to be
more truthful, I do this for hWnds. It always complains about lengths and
works.

I would be inclined to blit the DC to the screen on entry to this function.
That will show if it is the interpretation of the DC variable which is
faulty or how the code is implemented.

There are a lot of flags - it's worth copying a sample to start with and
going from there...
Iain
--
Iain Downs (DirectShow MVP)
Commercial Software Therapist
www.idcl.co.uk
 
 
 

IVMRMixerBitmap and GDI+ bitmap

Post by Pascal Clo » Fri, 03 Mar 2006 03:07:57


kapk4it153gh$ XXXX@XXXXX.COM ...

this changes nothing


what do you mean? up to now, i just save my managed bitmap to a file for
seeing if it is correct and it is.
 
 
 

IVMRMixerBitmap and GDI+ bitmap

Post by Peter Feld » Fri, 03 Mar 2006 03:39:29

"Pascal Cloup" < XXXX@XXXXX.COM > schrieb im Newsbeitrag



I don't know anything about c#/managed code, so you probably will have to
"translate" my suggestions...

You must "select" this bitmap-object into the/any desired HDC - so simply
typecasting your hbitmap to a hdc certainly won't work!
Your code should e.g. look (a little bit) like:

hdcScreen := CreateDC('DISPLAY', nil, nil, nil);
hdcMem := CreateCompatibleDC(hdcScreen);
SelectObject(hdcMem, m_hbitmap );

and _then_ you can set hdcMem as the HDC-param to VMRALPHABITMAP (and in
turn pass it to pVMRMixerBitmap->SetAlphaBitmap())

(of course you'll have to destroy hdcMem and hdcScreen again...)

--
Peter Feldbaumer
p dot feldbaumer at utanet dot at
 
 
 

IVMRMixerBitmap and GDI+ bitmap

Post by Iain » Fri, 03 Mar 2006 04:16:54

>> I would be inclined to blit the DC to the screen on entry to this

But you are saving the bitmap in managed (at least I assume so).

my suggestion is to verify that the hdc you think you've got is in fact an
hdc which represents the bitmap - that is to do it in the C++ code.


Iain
--
Iain Downs (DirectShow MVP)
Commercial Software Therapist
www.idcl.co.uk
 
 
 

IVMRMixerBitmap and GDI+ bitmap

Post by Pascal Clo » Fri, 03 Mar 2006 05:03:49

Hi,

Once the translation you suggested is done , this works.

So, the C# sequence is:
Bitmap b = new Bitmap( this.Width , this.Height ,
PixelFormat.Format32bppArgb );

g = Graphics.FromImage( b );

DoMyDrawings( g );

hr = videoPlayer.PrepareToBlend( g.GetHdc() , b.GetHbitmap() , true , 1f ,
b.Width , b.Height );


and the C++ Managed code is:
int VideoPlayer::PrepareToBlend( IntPtr hdc , IntPtr hBitmap , bool blend ,
float alpha , int width , int height )

{

.....

VMRALPHABITMAP vmrBitmap;

HDC hdcBmp = CreateCompatibleDC(reinterpret_cast<HDC>( hdc.ToPointer() ));
// Here, Simple cast not accepted by my compiler.

SelectObject( hdcBmp , (HGDIOBJ)hBitmap );
// But not a problem here!

vmrBitmap.hdc = hdcBmp;

.....
hr = pVMRMixerBitmap->SetAlphaBitmap( &vmrBitmap );

....

}



thanks to all

Pascal

"Peter Feldbaumer" < XXXX@XXXXX.COM > a rit dans le message de