How do a capture of a control and save to bitmap file?
-
Hello I want to do a capture of one control(custom control) in my project in memory and save directly this capture in a bitmap or jpg file. Help me please. Jdata
-
Hello I want to do a capture of one control(custom control) in my project in memory and save directly this capture in a bitmap or jpg file. Help me please. Jdata
Using Win32 APIs or MFC? Mark
Mark Salsbery Microsoft MVP - Visual C++ :java:
-
Using Win32 APIs or MFC? Mark
Mark Salsbery Microsoft MVP - Visual C++ :java:
both. i do this CDC dc; CRect rectClient; thecontrol.GetClientRect(&rectClient); HDC hdc = ::GetDC(thecontrol.m_hWnd); dc.Attach(hdc); CDC memDC; memDC.CreateCompatibleDC(&dc); CBitmap bm; bm.CreateCompatibleBitmap(&dc, rectClient.right, rectClient.bottom); CBitmap * oldbm = memDC.SelectObject(&bm); memDC.BitBlt(0, 0, rectClient.right, rectClient.bottom, &dc, 0, 0, SRCCOPY); here bm as done a screenshot of the control. i want to save this Cbitmap to file .bmp?? If you have other function!! thanks
-
both. i do this CDC dc; CRect rectClient; thecontrol.GetClientRect(&rectClient); HDC hdc = ::GetDC(thecontrol.m_hWnd); dc.Attach(hdc); CDC memDC; memDC.CreateCompatibleDC(&dc); CBitmap bm; bm.CreateCompatibleBitmap(&dc, rectClient.right, rectClient.bottom); CBitmap * oldbm = memDC.SelectObject(&bm); memDC.BitBlt(0, 0, rectClient.right, rectClient.bottom, &dc, 0, 0, SRCCOPY); here bm as done a screenshot of the control. i want to save this Cbitmap to file .bmp?? If you have other function!! thanks
Maybe:
CWindowDC ControlDC(&thecontrol);
CDC MemoryDC;
MemoryDC.CreateCompatibleDC(&ControlDC);
CRect ControlRect;
thecontrol.GetWindowRect(&ControlRect);
CImage ControlImage;
ControlImage.Create(ControlRect.Width(), ControlRect.Height(), 24, 0);
HGDIOBJ hOldBitmap = ::SelectObject(MemoryDC, (HBITMAP)ControlImage);
thecontrol.SendMessage(WM_PRINT, (WPARAM)(HDC)MemoryDC, PRF_ERASEBKGND | PRF_CLIENT | PRF_NONCLIENT);
::SelectObject(MemoryDC, hOldBitmap);
ControlImage.Save(_T("c:\\mycontrol.bmp"), ImageFormatBMP);Mark
Mark Salsbery Microsoft MVP - Visual C++ :java:
-
Maybe:
CWindowDC ControlDC(&thecontrol);
CDC MemoryDC;
MemoryDC.CreateCompatibleDC(&ControlDC);
CRect ControlRect;
thecontrol.GetWindowRect(&ControlRect);
CImage ControlImage;
ControlImage.Create(ControlRect.Width(), ControlRect.Height(), 24, 0);
HGDIOBJ hOldBitmap = ::SelectObject(MemoryDC, (HBITMAP)ControlImage);
thecontrol.SendMessage(WM_PRINT, (WPARAM)(HDC)MemoryDC, PRF_ERASEBKGND | PRF_CLIENT | PRF_NONCLIENT);
::SelectObject(MemoryDC, hOldBitmap);
ControlImage.Save(_T("c:\\mycontrol.bmp"), ImageFormatBMP);Mark
Mark Salsbery Microsoft MVP - Visual C++ :java:
CImage?? thanks
-
CImage?? thanks
CImage is declared in
atlimage.h
I used that so I wouldn't have to write code to save to a file - let GDI+ do it ;P You could use CBitmap instead (a DIBSection would make it easier) and write your own code to save the bitmap. MarkMark Salsbery Microsoft MVP - Visual C++ :java:
-
CImage is declared in
atlimage.h
I used that so I wouldn't have to write code to save to a file - let GDI+ do it ;P You could use CBitmap instead (a DIBSection would make it easier) and write your own code to save the bitmap. MarkMark Salsbery Microsoft MVP - Visual C++ :java:
ok i try but i have a error on ImageFormatBMP. undeclared identifier!!! i have done #include to have Cimage class but i have a problem on ImageFormatBMP thanks
-
CImage is declared in
atlimage.h
I used that so I wouldn't have to write code to save to a file - let GDI+ do it ;P You could use CBitmap instead (a DIBSection would make it easier) and write your own code to save the bitmap. MarkMark Salsbery Microsoft MVP - Visual C++ :java:
i have a black bmp file (Gdiplus::ImageFormatBMP) ty
-
ok i try but i have a error on ImageFormatBMP. undeclared identifier!!! i have done #include to have Cimage class but i have a problem on ImageFormatBMP thanks
Try Gdiplus::ImageFormatBMP Mark
Mark Salsbery Microsoft MVP - Visual C++ :java:
-
i have a black bmp file (Gdiplus::ImageFormatBMP) ty
I didn't know if WM_PRINT would work with your custom control. I suppose you can scrape it off the screen if it's visible:
CWindowDC ScreenDC(0);
CDC MemoryDC;
MemoryDC.CreateCompatibleDC(&ScreenDC);
CRect ControlRect;
thecontrol.GetWindowRect(&ControlRect);
CImage ControlImage;
ControlImage.Create(ControlRect.Width(), ControlRect.Height(), 24, 0);
HGDIOBJ hOldBitmap = ::SelectObject(MemoryDC, (HBITMAP)ControlImage);
MemoryDC.BitBlt(0, 0, ControlRect.Width(), ControlRect.Height(), &ScreenDC, ControlRect.left, ControlRect.top, SRCCOPY);
::SelectObject(MemoryDC, hOldBitmap);
ControlImage.Save(_T("c:\\testmy.bmp"), Gdiplus::ImageFormatBMP);Mark
Mark Salsbery Microsoft MVP - Visual C++ :java:
-
I didn't know if WM_PRINT would work with your custom control. I suppose you can scrape it off the screen if it's visible:
CWindowDC ScreenDC(0);
CDC MemoryDC;
MemoryDC.CreateCompatibleDC(&ScreenDC);
CRect ControlRect;
thecontrol.GetWindowRect(&ControlRect);
CImage ControlImage;
ControlImage.Create(ControlRect.Width(), ControlRect.Height(), 24, 0);
HGDIOBJ hOldBitmap = ::SelectObject(MemoryDC, (HBITMAP)ControlImage);
MemoryDC.BitBlt(0, 0, ControlRect.Width(), ControlRect.Height(), &ScreenDC, ControlRect.left, ControlRect.top, SRCCOPY);
::SelectObject(MemoryDC, hOldBitmap);
ControlImage.Save(_T("c:\\testmy.bmp"), Gdiplus::ImageFormatBMP);Mark
Mark Salsbery Microsoft MVP - Visual C++ :java:
It's works Excellent!!! THANKS