Click here to Skip to main content
15,899,314 members
Home / Discussions / Graphics
   

Graphics

 
GeneralRe: Shoemake's Mysterious Translation Controller (Take Two) Pin
Tim Craig14-Sep-08 14:34
Tim Craig14-Sep-08 14:34 
GeneralRe: Shoemake's Mysterious Translation Controller (Take Two) Pin
Steve Katic14-Sep-08 14:55
Steve Katic14-Sep-08 14:55 
GeneralRe: Shoemake's Mysterious Translation Controller (Take Two) [modified] Pin
Steve Katic14-Sep-08 15:13
Steve Katic14-Sep-08 15:13 
QuestionCreate real time graphical line chart from data save in txt file format Pin
yefeng_law13-Sep-08 6:52
yefeng_law13-Sep-08 6:52 
AnswerRe: Create real time graphical line chart from data save in txt file format Pin
Tim Craig13-Sep-08 12:03
Tim Craig13-Sep-08 12:03 
GeneralRe: Create real time graphical line chart from data save in txt file format Pin
yefeng_law20-Sep-08 7:15
yefeng_law20-Sep-08 7:15 
GeneralRe: Create real time graphical line chart from data save in txt file format Pin
Tim Craig21-Sep-08 18:25
Tim Craig21-Sep-08 18:25 
QuestionStrange error capturing the desktop to a bitmap Pin
rikshot13-Sep-08 5:48
rikshot13-Sep-08 5:48 
Hi
The following code produces a screen capture of the whole desktop to a .bmp file. It works fine when you have 16-bit color depth set at Windows display properties, but when you use it with 32-bit color depth, the image produced is crooked and disorted in a very strange way. I have tried absolutely everything to figure out what causes this, but nothing seems to work.

#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#include <fstream>

int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{
	HWND hWnd = GetDesktopWindow();
	HDC hDc = GetDC(hWnd);

	WINDOWINFO window_info;
	window_info.cbSize = sizeof(WINDOWINFO);
	GetWindowInfo(hWnd, &window_info);
	
	const unsigned width = window_info.rcClient.right - window_info.rcClient.left;
	const unsigned height = window_info.rcClient.bottom - window_info.rcClient.top;
	const unsigned size = ((width * 24 + 31) & ~31) / 8 * height;

	PSTR pixels = NULL;

	BITMAPINFO bitmap_info = {0};
	bitmap_info.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
	bitmap_info.bmiHeader.biWidth = width;
	bitmap_info.bmiHeader.biHeight = height;
	bitmap_info.bmiHeader.biPlanes = 1;
	bitmap_info.bmiHeader.biBitCount = 24;
	bitmap_info.bmiHeader.biCompression = BI_RGB;
	bitmap_info.bmiHeader.biSizeImage = size;

	HDC hCompatibleDc = CreateCompatibleDC(hDc);
	HBITMAP hBitmap = CreateDIBSection(NULL, &bitmap_info, DIB_RGB_COLORS, (void **)&pixels, NULL, 0);
	SelectObject(hCompatibleDc, hBitmap);
	BitBlt(hCompatibleDc, 0, 0, width, height, hDc, window_info.rcClient.left, window_info.rcClient.top, SRCCOPY);

	BITMAPFILEHEADER file_header = {0};
	file_header.bfType = 0x4d42;
	file_header.bfSize = sizeof(BITMAPFILEHEADER) + sizeof(BITMAPINFOHEADER) + size;
	file_header.bfOffBits = sizeof(BITMAPFILEHEADER) + sizeof(BITMAPINFOHEADER); 

	std::ofstream image("image.bmp");
	image.write((PSTR)&file_header, sizeof(BITMAPFILEHEADER));
	image.write((PSTR)&bitmap_info.bmiHeader, sizeof(BITMAPINFOHEADER));
	image.write(pixels, size);
	image.close();

	SelectObject(hCompatibleDc, NULL);
	DeleteObject(hBitmap);
	DeleteDC(hCompatibleDc);
	ReleaseDC(hWnd, hDc);

	return 0;
}</fstream></windows.h>


Does anyone have any clue to why this doesn't work? I've also tried to create a DC using the CreateDC function with TEXT("DISPLAY") and NULL parameters to create a device context that spans all display areas, but that produces the same error in the image using 32-bit color depth.
AnswerRe: Strange error capturing the desktop to a bitmap Pin
Mark Salsbery13-Sep-08 9:05
Mark Salsbery13-Sep-08 9:05 
QuestionHelp needed, DirectX 10 Sprite rendering problem Pin
Sikozu13-Sep-08 2:05
Sikozu13-Sep-08 2:05 
QuestionHow to improve drawing performance with GDI+? Pin
User 127827-Sep-08 12:44
User 127827-Sep-08 12:44 
AnswerRe: How to improve drawing performance with GDI+? Pin
Tim Craig8-Sep-08 9:57
Tim Craig8-Sep-08 9:57 
GeneralRe: How to improve drawing performance with GDI+? Pin
User 127828-Sep-08 13:10
User 127828-Sep-08 13:10 
GeneralRe: How to improve drawing performance with GDI+? Pin
Tim Craig8-Sep-08 14:25
Tim Craig8-Sep-08 14:25 
GeneralRe: How to improve drawing performance with GDI+? Pin
User 127828-Sep-08 15:09
User 127828-Sep-08 15:09 
QuestionVirtual World Pin
AndrewMcIntyre7-Sep-08 5:08
AndrewMcIntyre7-Sep-08 5:08 
QuestionDirect3D and 2D Rendering Pin
Raheel Anwar7-Sep-08 3:24
Raheel Anwar7-Sep-08 3:24 
Questionconvert .3d file in .x file Pin
sepel6-Sep-08 23:28
sepel6-Sep-08 23:28 
AnswerRe: convert .3d file in .x file Pin
Pete O'Hanlon7-Sep-08 23:29
mvePete O'Hanlon7-Sep-08 23:29 
GeneralRe: convert .3d file in .x file Pin
sepel8-Sep-08 0:33
sepel8-Sep-08 0:33 
GeneralRe: convert .3d file in .x file Pin
Pete O'Hanlon8-Sep-08 2:26
mvePete O'Hanlon8-Sep-08 2:26 
GeneralRe: convert .3d file in .x file Pin
sepel8-Sep-08 17:57
sepel8-Sep-08 17:57 
QuestionSaving image files in ARGB format (with transparency) Pin
pbalaga5-Sep-08 9:23
pbalaga5-Sep-08 9:23 
QuestionDirectX, OpenGL, WPF or XNA? Pin
Uri912-Sep-08 8:18
Uri912-Sep-08 8:18 
AnswerRe: DirectX, OpenGL, WPF or XNA? Pin
John_Adams2-Sep-08 19:26
John_Adams2-Sep-08 19:26 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.