Werbung: SecurityConsole.de verwaltet Ihre Computer mit Security Essentails aus der Cloud!
30 Tage kostenfrei testen und 20% Rabatt für Ihre Bestellung mit Promocode: WBF2685582
(Promocode gültig bis 31.12.2011)

Group:  English: Entertainment » microsoft.public.windowsmedia.sdk
Thread: IMediaBuffer: How to convert it into Bitmap and Vice versa

HTVi
TV Discussion Newsgroups

IMediaBuffer: How to convert it into Bitmap and Vice versa
hriday.musale[ at ]gmail.com 10/18/2008 9:05:45 PM
Hi,

I want to convert IMediaBuffer in into Bitmap (array of bytes and get
a HDC) and then draw new text on that HDC and convert the Bitmap
(array of buyes) to IMediaBuffer. And then this buffer will be pass to
WM Player by ProcessOutput function.

The complete operation will happen in DSP Video plug-in's
ProcessOutput function

Any help is appreciated.
Thanks in Advance
Re: IMediaBuffer: How to convert it into Bitmap and Vice versa
"Alessandro Angeli" <nobody[ at ]nowhere.in.the.net> 10/20/2008 5:18:08 PM
From: "hriday.musale[ at ]gmail.com"

[Quoted Text]
> I want to convert IMediaBuffer in into Bitmap (array of
> bytes and get a HDC) and then draw new text on that HDC
> and convert the Bitmap (array of buyes) to IMediaBuffer.
> And then this buffer will be pass to WM Player by
> ProcessOutput function.

AFAIK there is no way in GDI or GDI+ to create an HBITMAP or
HDC around a pre-allocated LPBYTE.

You need to allocate an in-memory HBITMAP and its HDC in
your DSP, copy the data from the input buffer to it
yourself, draw on the HDC, then copy from the HDC to the
output buffer. During both copies, you will need to perform
a line-by-line copy, taking the stride/pitch
(((VIDEOINFOHEADER*)DMO_MEDIA_TYPE::pbFormat)->bmiHeader.biWidth)
into account (it may be larger than the RECT specified in
((VIDEOINFOHEADER*)DMO_MEDIA_TYPE::pbFormat)->rcSource).



--
// Alessandro Angeli
// MVP :: DirectShow / MediaFoundation
// mvpnews at riseoftheants dot com
// http://www.riseoftheants.com/mmx/faq.htm


Re: IMediaBuffer: How to convert it into Bitmap and Vice versa
hriday.musale[ at ]gmail.com 10/21/2008 7:50:03 AM
On Oct 20, 10:18 am, "Alessandro Angeli" <nob...[ at ]nowhere.in.the.net>
wrote:
[Quoted Text]
> From: "hriday.mus...[ at ]gmail.com"
>
> > I want to convert IMediaBuffer in into Bitmap (array of
> > bytes and get a HDC) and then draw new text on that HDC
> > and convert the Bitmap (array of buyes) to IMediaBuffer.
> > And then this buffer will be pass to WM Player by
> > ProcessOutput function.
>
> AFAIK there is no way in GDI or GDI+ to create an HBITMAP or
> HDC around a pre-allocated LPBYTE.
>
> You need to allocate an in-memory HBITMAP and its HDC in
> your DSP, copy the data from the input buffer to it
> yourself, draw on the HDC, then copy from the HDC to the
> output buffer. During both copies, you will need to perform
> a line-by-line copy, taking the stride/pitch
> (((VIDEOINFOHEADER*)DMO_MEDIA_TYPE::pbFormat)->bmiHeader.biWidth)
> into account (it may be larger than the RECT specified in
> ((VIDEOINFOHEADER*)DMO_MEDIA_TYPE::pbFormat)->rcSource).
>
> --
> // Alessandro Angeli
> // MVP :: DirectShow / MediaFoundation
> // mvpnews at riseoftheants dot com
> //http://www.riseoftheants.com/mmx/faq.htm

Here is my code in the Process32Bit function in the DSP plugin. This
below code is after loop which process the pbTarget. This is plugin
wizard generated code.

HDC hDC = ::GetDC(NULL);

BITMAPINFO bi;
memset(&bi,0,sizeof(BITMAPINFO));
bi.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
bi.bmiHeader.biWidth = m_Width;
bi.bmiHeader.biHeight = m_Height;
bi.bmiHeader.biPlanes = 1;
bi.bmiHeader.biBitCount = 32;
bi.bmiHeader.biCompression = BI_RGB;
bi.bmiHeader.biSizeImage =
bi.bmiHeader.biWidth*bi.bmiHeader.biHeight*32/8;

::SetDIBitsToDevice(hDC,
0,0,
m_Width,
m_Height,
0,
0,
0,bi.bmiHeader.biHeight,
pbSource,&bi,DIB_RGB_COLORS);

HBITMAP hBmp = (HBITMAP)GetCurrentObject( hDC, OBJ_BITMAP );
HDC hMemDC = CreateCompatibleDC(hDC);
HGDIOBJ hOld = SelectObject(hMemDC, hBmp);

HBRUSH hBrush = CreateSolidBrush(RGB(0,0,0));

RECT rect = { 0, 0, m_Width-100, m_Height-100 };
FillRect(hDC, & rect, hBrush);
DeleteObject(hBrush);

SelectObject(hMemDC, hOld);
DeleteObject(hMemDC);

HBITMAP hBmp1 = (HBITMAP)GetCurrentObject( hDC, OBJ_BITMAP );
::GetBitmapBits(hBmp1,bi.bmiHeader.biWidth*bi.bmiHeader.biHeight*32/8,pbTarget);

But when the output is displayed, I see a black rectangle deing drawn
on the left top corner of WM Player (on top of WM Player) . Actually,
I would like to assign the modifed DC to output buffer so WM Player
can display it.
Here I want to create a in memory HBITMAP from pbSource, draw a
rectangle on that hbitmap and assign the changed HBITMAP to pbTarget.

What I am missing here?

Home | Search | Terms | Imprint Contact
Newsgroups Reader - provided by WiredBox.Net
Suche nach Orten, Städten, Postleitzahlen, Vorwahlen, Kfz-Kennzeichen