HDC to HDIB

I need to convert hdc to hdib data of 256 colors of size 180*120
But i didn't get output as required plz help me
{
 BITMAPINFO Binf;
 BITMAPINFOHEADER bi;int ki;
 HDC hMemDC = CreateCompatibleDC(hDC);
 int DCWidth  = GetDeviceCaps( hDC, HORZRES );
 int DCHeight = GetDeviceCaps( hDC, VERTRES );
 StretchBlt(hMemDC,0,0,180,120,hDC,0,0,DCWidth,DCHeight,SRCCOPY);

 bi.biSize   = sizeof(BITMAPINFOHEADER);//40;
 bi.biWidth   = 180;//Let it be constant width for our saving bitmaps
 bi.biHeight   = 120;//Let it be constant height for our saving bitmaps
 bi.biPlanes   = 1;
 bi.biBitCount  = 8;
 bi.biCompression = 0;
 bi.biSizeImage  = 21600; //This will be getted from dc
21600(wid*hei*numcolors);
 bi.biXPelsPerMeter = 0;
 bi.biYPelsPerMeter = 0;
 bi.biClrUsed  = 256; //This will also get from dc256
 bi.biClrImportant = 0;

 unsigned long nDIBSize=bi.biSizeImage + 256 * sizeof(RGBQUAD);
 void *pDIBData = GlobalAlloc(GMEM_FIXED,nDIBSize);
 Binf.bmiHeader = bi;
 CreateDIBSection(hMemDC,&Binf,DIB_RGB_COLORS,&pDIBData,NULL,NULL);
 ki=GetLastError();

 //m_hBmp = CreateCompatibleBitmap( m_hDC,GetDeviceCaps(m_hDC, HORZRES),
 //          GetDeviceCaps(m_hDC, VERTRES));
 DeleteDC(hMemDC);
GlobalFree(pDIBData);
}


0
it_srini (31)
9/23/2004 3:30:07 PM
vc.mfc 33608 articles. 0 followers. Follow

3 Replies
322 Views

Similar Articles

[PageSpeed] 23

There are some conceptual mstakes in your code.
when you do the stretchblt  on the memdc actually you are  doing it on a 1*1
memory bitmap because you haven't se;lected
a proper size bitmap before you call stretchblt(...).


Also this isn't right.although it is right for 180 * 120 sized bitmap, if
you change the width to something like 181 you can't simply multiply without
taking
into account the padding of the memory bitmaps(and that too of two variants
DIB and DDB):-

bi.biSizeImage  = 21600; //This will be getted from dc
> 21600(wid*hei*numcolors);

First of all what is that you want to do and we will do it for you. That is
better than posting logically incorrect code and asking it to be corrected.
We can't read minds :)

Thanks
Vipin


"srVas" <it_srini@gawab.com> wrote in message
news:u#zQqIYoEHA.516@TK2MSFTNGP09.phx.gbl...
> I need to convert hdc to hdib data of 256 colors of size 180*120
> But i didn't get output as required plz help me
> {
>  BITMAPINFO Binf;
>  BITMAPINFOHEADER bi;int ki;
>  HDC hMemDC = CreateCompatibleDC(hDC);
>  int DCWidth  = GetDeviceCaps( hDC, HORZRES );
>  int DCHeight = GetDeviceCaps( hDC, VERTRES );
>  StretchBlt(hMemDC,0,0,180,120,hDC,0,0,DCWidth,DCHeight,SRCCOPY);
>
>  bi.biSize   = sizeof(BITMAPINFOHEADER);//40;
>  bi.biWidth   = 180;//Let it be constant width for our saving bitmaps
>  bi.biHeight   = 120;//Let it be constant height for our saving bitmaps
>  bi.biPlanes   = 1;
>  bi.biBitCount  = 8;
>  bi.biCompression = 0;
>  bi.biSizeImage  = 21600; //This will be getted from dc
> 21600(wid*hei*numcolors);
>  bi.biXPelsPerMeter = 0;
>  bi.biYPelsPerMeter = 0;
>  bi.biClrUsed  = 256; //This will also get from dc256
>  bi.biClrImportant = 0;
>
>  unsigned long nDIBSize=bi.biSizeImage + 256 * sizeof(RGBQUAD);
>  void *pDIBData = GlobalAlloc(GMEM_FIXED,nDIBSize);
>  Binf.bmiHeader = bi;
>  CreateDIBSection(hMemDC,&Binf,DIB_RGB_COLORS,&pDIBData,NULL,NULL);
>  ki=GetLastError();
>
>  //m_hBmp = CreateCompatibleBitmap( m_hDC,GetDeviceCaps(m_hDC, HORZRES),
>  //          GetDeviceCaps(m_hDC, VERTRES));
>  DeleteDC(hMemDC);
> GlobalFree(pDIBData);
> }
>
>


0
vipin (697)
9/24/2004 7:32:54 AM
Hi ,
      I corrected that one stretching in to 180*120 bitmap. and also i got
suceeded in selecting newly stretched bitmap in to one hbitmap handle.
But i need to Convert that hbitmap in to dib bitmap bits. that will contain
header information and the imagebits and colormap . I need it in 256 colored
one pls help. Sorry for posting the incorrect code here. Any way i need a
help from u or send the code to my mail-id.

Thank U
Srii

"Vipin" <vipin@nospam.com> wrote in message
news:OhGrOcgoEHA.3392@TK2MSFTNGP15.phx.gbl...
> There are some conceptual mstakes in your code.
> when you do the stretchblt  on the memdc actually you are  doing it on a
1*1
> memory bitmap because you haven't se;lected
> a proper size bitmap before you call stretchblt(...).
>
>
> Also this isn't right.although it is right for 180 * 120 sized bitmap, if
> you change the width to something like 181 you can't simply multiply
without
> taking
> into account the padding of the memory bitmaps(and that too of two
variants
> DIB and DDB):-
>
> bi.biSizeImage  = 21600; //This will be getted from dc
> > 21600(wid*hei*numcolors);
>
> First of all what is that you want to do and we will do it for you. That
is
> better than posting logically incorrect code and asking it to be
corrected.
> We can't read minds :)
>
> Thanks
> Vipin
>
>
> "srVas" <it_srini@gawab.com> wrote in message
> news:u#zQqIYoEHA.516@TK2MSFTNGP09.phx.gbl...
> > I need to convert hdc to hdib data of 256 colors of size 180*120
> > But i didn't get output as required plz help me
> > {
> >  BITMAPINFO Binf;
> >  BITMAPINFOHEADER bi;int ki;
> >  HDC hMemDC = CreateCompatibleDC(hDC);
> >  int DCWidth  = GetDeviceCaps( hDC, HORZRES );
> >  int DCHeight = GetDeviceCaps( hDC, VERTRES );
> >  StretchBlt(hMemDC,0,0,180,120,hDC,0,0,DCWidth,DCHeight,SRCCOPY);
> >
> >  bi.biSize   = sizeof(BITMAPINFOHEADER);//40;
> >  bi.biWidth   = 180;//Let it be constant width for our saving bitmaps
> >  bi.biHeight   = 120;//Let it be constant height for our saving bitmaps
> >  bi.biPlanes   = 1;
> >  bi.biBitCount  = 8;
> >  bi.biCompression = 0;
> >  bi.biSizeImage  = 21600; //This will be getted from dc
> > 21600(wid*hei*numcolors);
> >  bi.biXPelsPerMeter = 0;
> >  bi.biYPelsPerMeter = 0;
> >  bi.biClrUsed  = 256; //This will also get from dc256
> >  bi.biClrImportant = 0;
> >
> >  unsigned long nDIBSize=bi.biSizeImage + 256 * sizeof(RGBQUAD);
> >  void *pDIBData = GlobalAlloc(GMEM_FIXED,nDIBSize);
> >  Binf.bmiHeader = bi;
> >  CreateDIBSection(hMemDC,&Binf,DIB_RGB_COLORS,&pDIBData,NULL,NULL);
> >  ki=GetLastError();
> >
> >  //m_hBmp = CreateCompatibleBitmap( m_hDC,GetDeviceCaps(m_hDC, HORZRES),
> >  //          GetDeviceCaps(m_hDC, VERTRES));
> >  DeleteDC(hMemDC);
> > GlobalFree(pDIBData);
> > }
> >
> >
>
>


0
it_srini (31)
9/27/2004 9:56:46 AM
Assuming you have a ddb, its a matter of calling the GetrDIBits(...) to get
the DIB.

Thanks
Vipin

"srVas" <it_srini@gawab.com> wrote in message
news:OOqFChHpEHA.744@TK2MSFTNGP10.phx.gbl...
> Hi ,
>       I corrected that one stretching in to 180*120 bitmap. and also i got
> suceeded in selecting newly stretched bitmap in to one hbitmap handle.
> But i need to Convert that hbitmap in to dib bitmap bits. that will
contain
> header information and the imagebits and colormap . I need it in 256
colored
> one pls help. Sorry for posting the incorrect code here. Any way i need a
> help from u or send the code to my mail-id.
>
> Thank U
> Srii
>
> "Vipin" <vipin@nospam.com> wrote in message
> news:OhGrOcgoEHA.3392@TK2MSFTNGP15.phx.gbl...
> > There are some conceptual mstakes in your code.
> > when you do the stretchblt  on the memdc actually you are  doing it on a
> 1*1
> > memory bitmap because you haven't se;lected
> > a proper size bitmap before you call stretchblt(...).
> >
> >
> > Also this isn't right.although it is right for 180 * 120 sized bitmap,
if
> > you change the width to something like 181 you can't simply multiply
> without
> > taking
> > into account the padding of the memory bitmaps(and that too of two
> variants
> > DIB and DDB):-
> >
> > bi.biSizeImage  = 21600; //This will be getted from dc
> > > 21600(wid*hei*numcolors);
> >
> > First of all what is that you want to do and we will do it for you. That
> is
> > better than posting logically incorrect code and asking it to be
> corrected.
> > We can't read minds :)
> >
> > Thanks
> > Vipin
> >
> >
> > "srVas" <it_srini@gawab.com> wrote in message
> > news:u#zQqIYoEHA.516@TK2MSFTNGP09.phx.gbl...
> > > I need to convert hdc to hdib data of 256 colors of size 180*120
> > > But i didn't get output as required plz help me
> > > {
> > >  BITMAPINFO Binf;
> > >  BITMAPINFOHEADER bi;int ki;
> > >  HDC hMemDC = CreateCompatibleDC(hDC);
> > >  int DCWidth  = GetDeviceCaps( hDC, HORZRES );
> > >  int DCHeight = GetDeviceCaps( hDC, VERTRES );
> > >  StretchBlt(hMemDC,0,0,180,120,hDC,0,0,DCWidth,DCHeight,SRCCOPY);
> > >
> > >  bi.biSize   = sizeof(BITMAPINFOHEADER);//40;
> > >  bi.biWidth   = 180;//Let it be constant width for our saving bitmaps
> > >  bi.biHeight   = 120;//Let it be constant height for our saving
bitmaps
> > >  bi.biPlanes   = 1;
> > >  bi.biBitCount  = 8;
> > >  bi.biCompression = 0;
> > >  bi.biSizeImage  = 21600; //This will be getted from dc
> > > 21600(wid*hei*numcolors);
> > >  bi.biXPelsPerMeter = 0;
> > >  bi.biYPelsPerMeter = 0;
> > >  bi.biClrUsed  = 256; //This will also get from dc256
> > >  bi.biClrImportant = 0;
> > >
> > >  unsigned long nDIBSize=bi.biSizeImage + 256 * sizeof(RGBQUAD);
> > >  void *pDIBData = GlobalAlloc(GMEM_FIXED,nDIBSize);
> > >  Binf.bmiHeader = bi;
> > >  CreateDIBSection(hMemDC,&Binf,DIB_RGB_COLORS,&pDIBData,NULL,NULL);
> > >  ki=GetLastError();
> > >
> > >  //m_hBmp = CreateCompatibleBitmap( m_hDC,GetDeviceCaps(m_hDC,
HORZRES),
> > >  //          GetDeviceCaps(m_hDC, VERTRES));
> > >  DeleteDC(hMemDC);
> > > GlobalFree(pDIBData);
> > > }
> > >
> > >
> >
> >
>
>


0
vipin (697)
10/4/2004 6:57:09 AM
Reply:

Similar Artilces:

how to get hwnd from hdc
Hi, I know how to get a HDC from HWND, but I am given a HDC from window media player and I want to correlate the mouse position with objects on my HDC. In order to use ScreenToClient I need the HDC's hwnd. How is that possible? If I use GetActiveWindow, I have an offset equal to the media player's menu and button panes. -- ------------------------------------------------------------------------- Music, Recipes, Photos, and more: http://www.sequoiagrove.dk "You don�t frighten us, English pig-dogs! Go and boil your bottoms, sons of a silly person. I blow my nose at you, so...

DrawTextW( hdc, strText, -1, rectB, DT_SINGLELINE); #2
Hi, I have a peice of a code for loading a icon and draw the text below the icon on the same button... i was sucessful in loading an icon but when tried with the DrawText() to insert a text, its not working and the problem is with the hdc parameter of DrawText function. void CNewButtonDlg::CallButton() { CString strText(""); //To place the text on the button RECT rectA = {180, 20, 270, 90}; //left, top, right, bottom //To nullify the error that parameter must be a LPRECT and not RECT type i have done so LPRECT rectB = &rectA; CDC my_newButto...

HDC
Env: WindowsXP, VC++6.0 Who can kindly tell me the different about using hDC1 or hDC2 inside OnDraw() below. CView::OnDraw(CDC* pDC) { HDC hDC1 = pDC->m_hDC; HDC hDC2 = ::GetDC(m_hWnd); } TIA William William wrote: > Env: WindowsXP, VC++6.0 > > Who can kindly tell me the different about using hDC1 or hDC2 inside > OnDraw() below. > > CView::OnDraw(CDC* pDC) > { > HDC hDC1 = pDC->m_hDC; > HDC hDC2 = ::GetDC(m_hWnd); > } > > TIA > William The DC passed to OnDraw is special in several ways. It is normally a CPaintDC, which i...

HDC to HDIB
I need to convert hdc to hdib data of 256 colors of size 180*120 But i didn't get output as required plz help me { BITMAPINFO Binf; BITMAPINFOHEADER bi;int ki; HDC hMemDC = CreateCompatibleDC(hDC); int DCWidth = GetDeviceCaps( hDC, HORZRES ); int DCHeight = GetDeviceCaps( hDC, VERTRES ); StretchBlt(hMemDC,0,0,180,120,hDC,0,0,DCWidth,DCHeight,SRCCOPY); bi.biSize = sizeof(BITMAPINFOHEADER);//40; bi.biWidth = 180;//Let it be constant width for our saving bitmaps bi.biHeight = 120;//Let it be constant height for our saving bitmaps bi.biPlanes = 1; bi.biBitCount = 8; bi.b...

get font from HDC
Hi, I would like to modify a function used to render some HTML and use the font I have choosen : // C functions int __stdcall DrawHTML( HDC hdc, // handle of device context LPCTSTR lpString, // address of string to draw int nCount, // string length, in characters LPRECT lpRect, // address of structure with formatting dimensions UINT uFormat // text-drawing flags ) { .... /* get the "default" font from the DC */ SavedD...

HDC and CDC
I am attempting for the first time to use CreateDibSection and am puzzled as to how to use HDC within the MFC framework. I can't see that CDC returns a handle, so I am wondering if these two are mutually exclusive. Is there a bridge between the handle and the class? "Steve Russell" <srussell@removethisinnernet.net> wrote in message news:uQoa24INEHA.624@TK2MSFTNGP11.phx.gbl... > I am attempting for the first time to use CreateDibSection and am puzzled as > to how to use HDC within the MFC framework. I can't see that CDC returns a > handle, so I am wonderin...

HDC Clipping issues
Hi, I am drawing some things in my view. I wish to draw stuff all over the client window, then set a clip rect, such as draw a line from one corner of the screen to another, but make sure that what I draw is only visible on a portion of the view. CMyView::OnDraw(CDC* pDC) { CMyDrawRoutines d; d.BeginDraw(pDC->m_hDC); d.DrawSomeStuffInEntireClientWindow(); CRect rc; GetClientRect(&rc); rc.DelfateRect(100,100,100,100); CRgn rgn; rgn.CreateRectRgnIndirect(&rc); d.SelectClipRgn(&rc); d.MoveTo(0,0); d.LineTo(rcClient.right, rcClient...

CDC/HDC????
I am trying to develop a print screen utility for a windows CE program. I am writing it in Embedded VC++ and running into some weirdness. My plan of action is to use GetClientRect() to find the location of the window, then loop through each pixel in that region and perform a GetPixel() to get the RGB value. My problem is that I need a HDC in order to perform GetPixel(). I used GetActiveWindow() to get an HWND, then used FromWindow() to get a CWnd pointer. I then tried the following line to get an HDC. HDC hdc=pWnd->GetWindowDC(); When I compile though I get the following error. erro...

Get BItmap From HDC
I'm stuck with getting CBitmap object from HDC. I'm using ecw SDK to view ecw files, and I need my soft to return CBitmap object of this .ecw file. in SDK there is a method: DrawImage( HDC DeviceContext, LPRECT pClipRect, IEEE8 dWorldTLX, IEEE8 dWorldTLY, IEEE8 dWorldBRX, IEEE8 dWorldBRY ); wich works just fine, it draws picture into givet device context. DrawImage(hdc, &m_Rect, m_dTLX, m_dTLY, m_dBRX, m_dBRY); CBitmap bitmap; CBitmap * bmp=bitmap.FromHandle((HBITMAP)hdc); is this right?? if DrawImage method drawed picture into HDC already?. If you have an HDC, and it has a bi...

how to make a cdc from a hdc ?
I have a HDC, is it possible to make a CDC from it? thanks, bn You can do this: CDC cDC; cDC.Attach(hdc); tankc "bn" <b@b.com> wrote in message news:%23tSzyNJ$EHA.3372@TK2MSFTNGP10.phx.gbl... > I have a HDC, is it possible to make a CDC from it? > > thanks, > bn > > tthere aretwo ways CDC dc; dc.Attach(hdc); //do ur stuff dc.Detach(); or CDC dc=CDC::FromHandle(hdc); //no need to detach. "bn" wrote: > I have a HDC, is it possible to make a CDC from it? > > thanks, > bn > > > The second one sho...

Rookie Q: Release HDC?
Hi, Imagine a little class like this: class CMyClass { public: CMyClass(HDC hDC) { m_hDC = hDC; } HDC GetHDC() { return m_hDC; } private: HDC m_hDC; } Now, in my CMyApp::OnView I do this: void CMyApp::OnView(CDC* pDC) { CMyClass mc(pDC->m_hDC); } Now, HDC is just an UINT, and all I am passing is this number. I shouldn't have to do any relasing of anything, do I? Or does my CMyClass class destructor have to do a DeleteObject(m_hDC) or something? Lisa The HDC is part of the CDC class. Be sure not to delete it, or even store it (except i...

How do I tell what HDC has a HBITMAP selected?
How do I tell which HDC has a specific HBITMAP selected? I am using the ImageList_GetImageInfo() function to get direct access to the HBITMAP in the imagelist. The problem is the system keeps this bitmap selected into a memory DC, so I can't select it into my DC to perform a BitBlt from it. There is a KB article that tells me to use the CopyImage function. CopyImage is terribly slow. Any ideas? ...

Load Tif file in memory hDC
How do I load a TIF file in memory hDC and save it back to another file after some processing using DrawText. I want to use the memory hDC because I dont want to display the image. Is there an example for doing this. Asfar wrote: > How do I load a TIF file in memory hDC and save it back to another file > after some processing using DrawText. > > I want to use the memory hDC because I dont want to display the image. > > Is there an example for doing this. > > I am using Cximage to do this. See here http://www.codeproject.com/bitmap/cximage.asp ...

DrawTextW( hdc, strText, -1, rectB, DT_SINGLELINE);
Hi, I have a peice of a code for loading a icon and draw the text below the icon on the same button... i was sucessful in loading an icon but when tried with the DrawText() to insert a text, its not working and the problem is with the hdc parameter of DrawText function. void CNewButtonDlg::CallButton() { CString strText(""); //To place the text on the button RECT rectA = {180, 20, 270, 90}; //left, top, right, bottom //To nullify the error that parameter must be a LPRECT and not RECT type i have done so LPRECT rectB = &rectA; CDC my_newButto...

slower BitBlt from unmanaged mem into C# hDC than old VB6
BitBlt'ing from unmanaged memory into an hDC obtained in a managed (C#) program takes 50-100% longer than the same BitBlt into an hDC obtained in an unmanaged (old VB6) program. My ShowPic() function resides in a DLL written in straight C. It reads a JPEG into memory allocated within the unmanaged DLL and then StretchDIBits()s it to the hDC passed. Some ancient VB6 code called it in a Paint event: Private Sub Picture1_Paint() ShowPic(Picture1.hdc, ...) End Sub Here is the C# code that is almost 100% slower: private void picObj1_Paint(object sender, System.Windows....

Panasonic HDC-SD5 AVCHD 3CCD Flash Memory High Definition Camcorder with 10x Optical Image Stabilization w/DVD Burner
Price:Too low to display Image: http://thediscountguru.info/image.php?id=B000YT5R28 Best deal: http://thediscountguru.info/index.php?id=B000YT5R28 Works great but in low light conditions the video isn't that great. Well lit and sunny areas the HandyCam captures great HD video. I have owned the camera for 2 weeks now and am returning it. I currently own 3 other video cameras, but this is my forst HD camera. Everything about the camera is wonderful except for one MAJOR flaw, there is a high pitched whine when I play back the vodeo through the camera. It is quite noticeable to say th...