Solved

How to capture a DIB to a 24 bpp

Posted on 2001-08-30
4
445 Views
Last Modified: 2008-02-01
I would like to capture a bitmap from my screen and store it in a format which is independent of the resolution. More Specifically, I would like to store it always in a 24 bpp file. Is there any way to do this.
   However I cannot use GetDIBits(), because of performance issues.
    This is because i get the buffer directly from surface memory(using directx) and i will not be using windows gdi functions because of there slower performance.




0
Comment
Question by:sinha_sandeep
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
4 Comments
 
LVL 49

Expert Comment

by:DanRollins
ID: 6443755
>>However I cannot use GetDIBits(), because of performance issues.

There is no way to get the image data to a file without using GetDIBits().  Anyway, the performce issues will be all about the transfer of the data to disk -- not any copying of bits from memroy buffer to memroty buffer.

I can tell you how to take an image from the screen and blit it onto a 24bpp memory DC and from there move it to a file.  But this other issue (refusal to use GetDIBits) needs to be addressed first.

-- Dan
0
 
LVL 1

Accepted Solution

by:
AlexReser earned 200 total points
ID: 6444069
This code shows how to drop whole screen in 24-bpp BMP-file:

int iScrWidth = GetSystemMetrics(SM_CXSCREEN);
int iScrHeight = GetSystemMetrics(SM_CYSCREEN);

HDC hdcScreen = GetDC(NULL);

BITMAPINFO bmpInfo;
bmpInfo.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
bmpInfo.bmiHeader.biWidth              = iScrWidth;
bmpInfo.bmiHeader.biHeight             = iScrHeight;
bmpInfo.bmiHeader.biPlanes             = 1;
bmpInfo.bmiHeader.biBitCount           = 24;
bmpInfo.bmiHeader.biCompression        = BI_RGB;
bmpInfo.bmiHeader.biSizeImage          = 0;
bmpInfo.bmiHeader.biXPelsPerMeter      = 0;
bmpInfo.bmiHeader.biYPelsPerMeter      = 0;
bmpInfo.bmiHeader.biClrUsed            = 0;
bmpInfo.bmiHeader.biClrImportant       = 0;

void *pvBits = NULL;
HBITMAP hBitmap = CreateDIBSection(hdcScreen,&bmpInfo,DIB_RGB_COLORS,&pvBits,NULL,0);
HDC hdcCompatible = CreateCompatibleDC(hdcScreen);
HBITMAP hOldBitmap = (HBITMAP)SelectObject(hdcCompatible,hBitmap);
BOOL b = BitBlt(hdcCompatible,0,0,iScrWidth,iScrHeight,hdcScreen,0,0,SRCCOPY);

HANDLE hFile = CreateFile("yourbmp.bmp",GENERIC_WRITE,FILE_SHARE_WRITE,NULL,
           CREATE_ALWAYS,FILE_ATTRIBUTE_NORMAL,NULL);
if (hFile != INVALID_HANDLE_VALUE)
{
   DWORD dwCnt;
   char z[14];
   ZeroMemory(z,14);
   strcpy(z,"BM8");
   z[4] = 0x24;
   z[10] = 0x36;
   WriteFile(hFile,z,14,&dwCnt,NULL);
   WriteFile(hFile,(char*)&bmpInfo,sizeof(BITMAPINFO)-4,&dwCnt,NULL);
   WriteFile(hFile,(char*)pvBits,iScrWidth*iScrHeight*3,&dwCnt,NULL);
   CloseHandle(hFile);
}    
   
SelectObject(hdcCompatible,hOldBitmap);
DeleteDC(hdcCompatible);
DeleteObject(hBitmap);
ReleaseDC(NULL,hdcScreen);
0
 
LVL 11

Expert Comment

by:griessh
ID: 6865651
I think you forgot this question. I will ask Community Support to close it unless you finalize it within 7 days. Unless there is objection or further activity,  I will suggest to accept "AlexReser" comment(s) as an answer.

If you think your question was not answered at all, you can post a request in Community support (please include this link) to refund your points.
The link to the Community Support area is: http://www.experts-exchange.com/commspt

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!
======
Werner
0
 
LVL 5

Expert Comment

by:Netminder
ID: 6886455
Per recommendation, force-accepted by
Netminder
Community Support Moderator
Experts Exchange
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

  Included as part of the C++ Standard Template Library (STL) is a collection of generic containers. Each of these containers serves a different purpose and has different pros and cons. It is often difficult to decide which container to use and …
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question