Find the fastest screenshot function! Preferably within 50 ms!

Source: Internet
Author: User
Tags dell latitude
Find the fastest screenshot function! Preferably within 50 ms! Delphi/Windows SDK/API
Http://www.delphi2007.net/DelphiMultimedia/html/delphi_20061024164940207.html
The screenshot taken by getdc takes about 180 ms. This is obviously too slow for remote control,
Is there any faster screenshot method.
I heard that setting the system re-draw Hook can only capture the changed part of the screen, thus improving the speed.
How can this hook method be used?
There is another way to do it, as long as it is fast enough!

Procedure tform1.cjt _ getscreen (VAR mybmp: tbitmap; drawcur: Boolean );
VaR
Cursorx, cursory: integer;
DC: HDC;
Mycan: TCanvas;
R: trect;
Drawpos: tpoint;
Mycursor: ticon;
HLD: hwnd;
Threadld: DWORD;
MP: tpoint;
Piconinfo: ticoninfo;
Begin
Mybmp: = tbitmap. Create; {create a BMP map}
Mycan: = TCanvas. Create; {screen capture}
DC: = getwindowdc (0 );
Try
Mycan. Handle: = Dc;
R: = rect (0, 0, screen. Width, screen. Height );
Mybmp. Width: = R. Right;
Mybmp. Height: = R. bottom;
Mybmp. Canvas. copyrect (R, mycan, R );
Finally
Releasedc (0, DC );
End;
Mycan. Handle: = 0;
Mycan. Free;
If drawcur then {draw the mouse image}
Begin
Getcursorpos (drawpos );
Mycursor: = ticon. Create;
Getcursorpos (MP );
HLD: = windowfrompoint (MP );
Threadld: = getwindowthreadprocessid (HLD, nil );
Attachthreadinput (getcurrentthreadid, threadld, true );
Mycursor. Handle: = getcursor ();
Attachthreadinput (getcurrentthreadid, threadld, false );
Geticoninfo (mycursor. Handle, piconinfo );
Cursorx: = drawpos. X-round (piconinfo. xhotspot );
Cursory: = drawpos. Y-round (piconinfo. yhotspot );
Mybmp. Canvas. Draw (cursorx, cursory, mycursor); {draw the mouse}
Deleteobject (piconinfo. hbmcolor); {two bitmap objects are created when geticoninfo is used. You need to manually release these two objects}
Deleteobject (piconinfo. hbmmask); {otherwise, after calling him, he will create a bitmap. Multiple calls will be generated until the resources are exhausted}
Mycursor. releasehandle; {release the Array Memory}
Mycursor. Free; {release the mouse pointer}
End;
End;

This function should be good.

This function is executed in the thread using getdc. It still uses 172 Ms on my computer.

Can I send a printscreen key message?
It is equivalent to pressing the ghost screen key of printscreen,
Use the Clipboard data.

Blog.joycode.com/jiangsheng/posts/#10.aspx

To jiangsheng (Jiang Sheng. Net [MVP]):
You areArticleIt is mentioned that the system hook is used to intercept re-draw messages.Source codeI can't understand it. How can I intercept it with Delphi and how can I capture the changed part of the screen?

I also heard that DirectX can be used to directly access the video memory, but how can I use direcxx to take screenshots?
How can I Capture screenshots using delphix (the Delphi Component that encapsulates direcxx?

Up

Mark

Benchmarks shows that direcxx is much slower then GDI
I don't know delphi. If you don't know C ++ you can rewrite all Windows API CILS in Delphi.

If the landlord is willing to give the score, I can help you compile an ultra-fast graph loading function with the compression function.

If you want to read the image data from the clipboard and save it as a BMP file, it is also very simple:

First, send a printscreen key and save it by using the savetofile () method of the image control!

VNC does not have a full Delphi source, but it has delphi components, but the core layer is still the C ++ DLL.

In addition, it is best for the landlord to figure out that the 50 ms you mentioned is for your machine configuration. It may be within 50 ms on other machines, but put it on your machine is not the case.
OneProgramPersonnel and their own demands are all the same. What would you do if your customers put forward similar demands?

If you want to speed up, you can only use the driver level.

To mwy654321 (for you unconditionally ):
How many points do you need? I will post another post.CodeGive it to me!

Learning, follow up ~~~~~

// The mwy654321 method is as follows:
Uses clipbrd;

Procedure tform1.timer1timer (Sender: tobject );
Begin
Keybd_event (vk_snapshot, 0, 0, 0 );
Keybd_event (vk_snapshot, 0, keyeventf_keyup, 0 );
If not clipboard. hasformat (cf_bitmap) Then exit;
Image1.picture. bitmap. loadfromclipboardformat (cf_bitmap,
Clipboard. getashandle (cf_bitmap), 0 );
End;

First, you do not need to set system hooks for this application, but the method will be slower.
Second, do not use copyrect, because copyrect calls the stretchblt, directly using bitblt is faster
For bitblt,

First, you do not need to set system hooks for this application, but the method will be slower.
Second, do not use copyrect, because copyrect calls the stretchblt, directly using bitblt is faster
For bitblt, my laptop test results are 1024x768 only need 3 MS
If the time required by the landlord's machine exceeds 50 ms, it only means that the host's machine's video card is too bad and should be changed immediately
The performance of bitblt is generally irrelevant to the CPU performance, mainly related to the performance of the video card.
Example:
Note: For performance testing, in my example
Caption: = caption + 'OK ';
This sentence seems nonsense, but it is essential because bitblt will return immediately and hand it over to the GPU on the video card for related operations.
This sentence caption: = caption + 'OK'; is to ensure that all bitblt GPU operations are completed. Otherwise, if there is no such sentence,
The time difference is close to 0.

Procedure tform1.button1click (Sender: tobject );
VaR
Oldtick, newtick: DWORD;
Abit: tbitmap;
I: integer;
DC: HDC;
Begin
Abit: = tbitmap. Create;
Try
Abit. Width: = screen. width;
Abit. Height: = screen. height;
Oldtick: = gettickcount;
For I: = 0 to 999 do
Begin
DC: = getdc (hwnd_desktop );
Win32check (bitblt (abit. Canvas. Handle, I mod 10, I mod 10, abit. Width, abit. Height, DC, 0, 0, srccopy ));
Releasedc (hwnd_desktop, DC );
End;
Caption: = caption + 'OK ';
Newtick: = gettickcount;
Finally
Abit. Free;
End;
Beep ();
Showmessage (format ('% u-% u = % d', [newtick, oldtick, newtick-oldtick]);
End;


Ask the upstairs. Why is a loop here? Isn't bitblt okay?
For I: = 0 to 999 do
Begin
DC: = getdc (hwnd_desktop );
Win32check (bitblt (abit. Canvas. Handle, I mod 10, I mod 10, abit. Width, abit. Height, DC, 0, 0, srccopy ));
Releasedc (hwnd_desktop, DC );
End;

Back upstairs: I made a loop to test bitblt performance.
Because the gettickcount precision is only 10 ms, and a bitblt is smaller than 10 ms
In this way, you can use the total time/number of times to calculate the time consumption each time.

For the print screen and paste from clipboard method provided by many people upstairs, I can only say this method is too weak.

First, poor performance
Second, it destroys the clipboard)

But do not use the clipboard for remote control of the host.

To spirit_sheng (laosheng ):
I used your method to test it on my machine. The other method is almost the same, and the time consumption is still 170 ~ 180 ms.
In addition, you said that setting system hooks would be slower. Why? I heard that this method is used by Radmin!
This is the code after I slightly modified your code. Is it okay?
Procedure bitblt_capscreen (astream: tmemorystream; left, top, width, height: integer );
VaR
Abit: tbitmap;
DC: HDC;
Begin
Abit: = tbitmap. Create;
Try
Abit. Width: = screen. width;
Abit. Height: = screen. height;
DC: = getdc (hwnd_desktop );
Win32check (bitblt (abit. Canvas. Handle, 0, 0, abit. Width, abit. Height, DC, 0, 0, srccopy ));
Releasedc (hwnd_desktop, DC );
// Caption: = caption + 'OK ';
Abit. savetostream (astream );
Finally
Abit. Free;
End;
End;
I removed caption: = caption + 'OK'; it's also normal!

The landlord posted your machine environment.
My Dell Latitude d600
CPU Intel (r) Pentium (r) m processor 725 (1.6 GHz)
Graphics card ATI mobility radeontm 9000 graphics card with 32 mb ddr memory
Windows XP profres0000sp2 (Simplified Chinese)
On my machine, the 1024x768 only takes 3 ms, and you say 170 ~ 180 MS, the difference is too big

To: The landlord, my caption: = caption + 'OK'; mainly based on timing considerations
Because bitblt is returned immediately

My machine is integrated graphics card. I heard that the Integrated Video Card has no video memory, and the memory is used in the main memory!
My machine is 2.6 GHz CPU, memory is 512 MB, and the operating system is Windows2000 Server

Ask spirit_sheng (laosheng)
I use your code,
I heard it soon.
Beep ();
However, showmessage only jumps out after several seconds. Why?
Showmessage (format ('% u-% u = % d', [newtick, oldtick, newtick-oldtick]);

To: Upstairs
This is what I said in my post. After you add the caption: = caption + 'OK', beep will not appear soon.
The bitblt function will return soon and will be handed over to the video card.
The showmessage operation also needs to be completed by the video card, so it will wait until the GPU is available to continue execution.

To: The landlord, your Integrated Video Card is too bad. It is king to change the video card.

You cannot ask the customer to change the record as well :)

If the bitblt method is tested cyclically, getdc may take more time.

You can look at this http://www.delphibox.com/article.asp? ArticleID = 3710 remote screen transfer difference

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.