Solved

32bpp->24bpp with BitBlt/StretchBlt

Posted on 2002-03-07
13
1,477 Views
Last Modified: 2007-12-19
In my program, it is necessary to convert the screen capture image from the screen's bit depth (usually
32bpp) to a 24bit format. With this code, I get about 0.5 to 1.0 seconds of lag (system freeze; the
mouse cannot be moved) during StretchBlt() when converting from my desktop depth of 32bits to 24bits.
As far as I can tell, this could perhaps be windows XP dependant?

Here's the code:

HBITMAP Bitmap;
int ScreenWidth, ScreenHeight, Width, Height, Scale;
HDC DesktopDC, CaptureDC;
BITMAPINFO BitmapInfo;
unsigned char *Data;

Scale = 50;
DesktopDC = GetDC(GetDesktopWindow());
ScreenWidth = GetDeviceCaps(DesktopDC, HORZRES);
ScreenHeight = GetDeviceCaps(DesktopDC, VERTRES);
Width = (ScreenWidth * Scale) / 100;
Height = (ScreenHeight * Scale) / 100;

memset(&BitmapInfo.bmiHeader, 0, sizeof(BitmapInfo.bmiHeader));
BitmapInfo.bmiHeader.biWidth = Width;
BitmapInfo.bmiHeader.biHeight = Height;
BitmapInfo.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
BitmapInfo.bmiHeader.biPlanes = 1;
BitmapInfo.bmiHeader.biBitCount = 24;
BitmapInfo.bmiHeader.biCompression = BI_RGB;

CaptureDC = CreateCompatibleDC(DesktopDC);
Bitmap = CreateDIBSection(DesktopDC, &BitmapInfo, DIB_RGB_COLORS, (void **)&Data, 0, 0);

SelectObject(CaptureDC, Bitmap);
StretchBlt(CaptureDC, 0, 0, Width, Height, DesktopDC, 0, 0, ScreenWidth, ScreenHeight, SRCCOPY); //
1 second freeze occurs here...

Any suggestions? It seems as if StrechBlt() is freezing up due to having to convert from 32bpp to 24bpp.
I have the exact same problem when doing BitBlt() from the screen to a bitmap of similar size.
0
Comment
Question by:Olympus
[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
  • 6
  • 2
  • 2
  • +2
13 Comments
 
LVL 86

Expert Comment

by:jkr
ID: 6848482
This behaviour is not a big surprise - it's the sheer amount of data that has to be processed...
0
 

Author Comment

by:Olympus
ID: 6848494
Yes, but this behaviour is non existant on 9x platforms. (Confirmed this morning.) Windows shouldn't be using realtime priority whilst processing the data. Is there a better way around this?
0
 
LVL 86

Expert Comment

by:jkr
ID: 6848591
>>Yes, but this behaviour is non existant on 9x platforms

You seem to forget that since NT4, the GDI has been moved into kernel space - it should work like Win9x on NT3.51 :o)
0
Independent Software Vendors: 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!

 
LVL 1

Expert Comment

by:senohp
ID: 6848901
The code consumes large amount of memory. What is the size of your machine's available physical memory ? It seems to me that the 500ms wait is caused by memory swapping.

If you still plan use the codes in a machine with a small amount of available memory, change the code to use a multi-thread mechanisme (of course with critical section locks). In this mechanisme, your user-interface is still active (e.g. mouse & keyboard is still usable) while waiting the memory swap complete.

Regards,


Seno Hardijanto
0
 

Author Comment

by:Olympus
ID: 6848909
Memory is not the concern.. i have over 250 megs free at any given time; and PLUS the code causes ZERO cpu freeze on my 98 partition.
0
 

Author Comment

by:Olympus
ID: 6848919
(This is not being run on an application with a GUI.)
0
 
LVL 1

Expert Comment

by:senohp
ID: 6849646
You're right;

I test your codes with my XP machine, there is no glitch in memory utilization, only in CPU usage (up to 50%). But in my environment there is no difference whether I use 16 bits or 32 bits screen depth, and ScretchBlt function call consumes CPU only about 100-200 ms (I use PIII 900Mhz).

Some of the GDI call were not performed by the CPU itself. The processor only relay the calls to the graphic adapter. So, I think you need to concern about the graphic adapter.
0
 

Author Comment

by:Olympus
ID: 6851228
There is no easy way to do the bpp conversion better with API functions?
0
 
LVL 11

Expert Comment

by:griessh
ID: 6955300
Dear Olympus

I think you forgot this question. I will ask Community Support to close it unless you finalize it within 7 days. You can always request to keep this question open. But remember, experts can only help you if you provide feedback to their questions.
Unless there is objection or further activity,  I will suggest to accept

     "jkr"

comment(s) as an answer.

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

Author Comment

by:Olympus
ID: 6956406
Well senohp was able to reproduce the problem; is there a way to do this with GetDIBits and StretchDIBits to get rid of the delays in BitBlt and StretchBlt?
0
 
LVL 6

Expert Comment

by:Mindphaser
ID: 7036221
Please update and finalize this old, open question. Please:

1) Award points ... if you need Moderator assistance to split points, comment here with details please or advise us in Community Support with a zero point question and this question link.
2) Ask us to delete it if it has no value to you or others
3) Ask for a refund so that we can move it to our PAQ at zero points if it did not help you but may help others.

EXPERT INPUT WITH CLOSING RECOMMENDATIONS IS APPRECIATED IF ASKER DOES NOT RESPOND.

Thanks,

** Mindphaser - Community Support Moderator **

P.S.  Click your Member Profile, choose View Question History to go through all your open and locked questions to update them.
0
 

Author Comment

by:Olympus
ID: 7036329
3; refund would be best.
0
 
LVL 6

Accepted Solution

by:
Mindphaser earned 0 total points
ID: 7036400
Points refunded and moved to PAQ

** Mindphaser - Community Support Moderator **
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

This article will show you some of the more useful Standard Template Library (STL) algorithms through the use of working examples.  You will learn about how these algorithms fit into the STL architecture, how they work with STL containers, and why t…
Container Orchestration platforms empower organizations to scale their apps at an exceptional rate. This is the reason numerous innovation-driven companies are moving apps to an appropriated datacenter wide platform that empowers them to scale at a …
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

734 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