Articles   Members Online:
-Article/Tip Search
-News Group Search over 21 Million news group articles.
-Delphi/Pascal
-CBuilder/C++
-C#Builder/C#
-JBuilder/Java
-Kylix
Member Area
-Home
-Account Center
-Top 10 NEW!!
-Submit Article/Tip
-Forums Upgraded!!
-My Articles
-Edit Information
-Login/Logout
-Become a Member
-Why sign up!
-Newsletter
-Chat Online!
-Indexes NEW!!
Employment
-Build your resume
-Find a job
-Post a job
-Resume Search
Contacts
-Contacts
-Feedbacks
-Link to us
-Privacy/Disclaimer
Embarcadero
Visit Embarcadero
Embarcadero Community
JEDI
Links
How to save a screen shot to a JPEG file Turn on/off line numbers in source code. Switch to Orginial background IDE or DSP color Comment or reply to this aritlce/tip for discussion. Bookmark this article to my favorite article(s). Print this article
29-Aug-02
Category
Files Operation
Language
Delphi 3.x
Views
81
User Rating
No Votes
# Votes
0
Replies
0
Publisher:
DSP, Administrator
Reference URL:
DKB
			Author: Tomas Rutkauskas

How can I write a screen capture not to a bitmap file but to a JPEG file?

Answer:
1   
2   procedure ScreenShot(x: integer; y: integer; Width: integer; Height: integer; bm: 
3   TBitmap);
4   var
5     dc: HDC;
6     lpPal: PLOGPALETTE;
7   begin
8     {test width and height}
9     if ((Width = 0) or (Height = 0)) then
10    begin
11      exit;
12    end;
13    bm.Width := Width;
14    bm.Height := Height;
15    {get the screen dc}
16    dc := GetDc(0);
17    if (dc = 0) then
18    begin
19      exit;
20    end;
21    {do we have a palette device?}
22    if (GetDeviceCaps(dc, RASTERCAPS) and RC_PALETTE = RC_PALETTE) then
23    begin
24      {allocate memory for a logical palette}
25      GetMem(lpPal, sizeof(TLOGPALETTE) + (255 * sizeof(TPALETTEENTRY)));
26      {zero it out to be neat}
27      FillChar(lpPal^, sizeof(TLOGPALETTE) + (255 * sizeof(TPALETTEENTRY)), #0);
28      {fill in the palette version}
29      lpPal^.palVersion := $300;
30      {grab the system palette entries}
31      lpPal^.palNumEntries := GetSystemPaletteEntries(dc, 0, 256, lpPal^.palPalEntry);
32      if (lpPal^.PalNumEntries < > 0) then
33      begin
34        {create the palette}
35        bm.Palette := CreatePalette(lpPal^);
36      end;
37      FreeMem(lpPal, sizeof(TLOGPALETTE) + (255 * sizeof(TPALETTEENTRY)));
38    end;
39    {copy from the screen to the bitmap}
40    BitBlt(bm.Canvas.Handle, 0, 0, Width, Height, Dc, x, y, SRCCOPY);
41    {release the screen dc}
42    ReleaseDc(0, dc);
43  end;
44  
45  procedure TForm1.Button1Click(Sender: TObject);
46  var
47    bm: TBitmap;
48    jp: TJPEGImage;
49  begin
50    bm := TBitmap.Create;
51    ScreenShot(0, 0, Screen.Width, Screen.Height, bm);
52    jp := TJPEGImage.Create;
53    jp.Assign(bm);
54    bm.free;
55    jp.SaveToFile('Test.jpg');
56    jp.Free;
57  end;


			
Vote: How useful do you find this Article/Tip?
Bad Excellent
1 2 3 4 5 6 7 8 9 10

 

Advertisement
Share this page
Advertisement
Download from Google

Copyright © Mendozi Enterprises LLC