Board index » delphi » Re: screen capture

Re: screen capture


2005-10-07 10:05:20 PM
delphi200
Jason,
See if this is close to what you are trying to pull off:
www.eonclash.com/ViewProduct.php I wrote it quite a few
years ago, but the concepts still apply. It basically shows how to get the
transparancy so that controls under your control will show thru. If its not
what you need can you post a sample to B.P.A. If so I will take a look at it
and see what I can do.
Jeremy
"Jason" <XXXX@XXXXX.COM>writes
Quote
The component to put transparent needs to know what to put behind. So it
has an Event "OnBackgroundDraw"

and in their example: Canvas.Draw(0, 0, Image1.Picture.Graphic); // canvas
is the component canvas

It works fine, it put the image on the background and it makes the sense
of transparency. But the problem is if I have more objects in the form?
Labels, Edits etc they are disappear because the are not included in the
Image1.Picture.Graphic. I need something bigger lets say
Form1.Picture.Graphic but only the specific area, 200x200.

Thanks


"Jeremy Darling" <XXXX@XXXXX.COM>writes
news:43458a67$XXXX@XXXXX.COM...
>Jason,
>What are you descending from for your component? If you are comming
>down from TGraphicControl you can pull off transparency w/o having to
>paint the background yourself.
>
>You can use the TCanvas.CopyMode property and TCanvas.CopyRect method to
>retrieve only the area of the image that you need and place it onto your
>canvas in the manor you wish. Their are also quite a few other copy
>methods. The GDI and GDI+ API's also have different blt and bitblt
>functions that can achieve what you are looking for.
>
>Post up a bit more info on what your trying to achieve :) and I am sure
>someone will give you the answer that you need.
>
>Jeremy
>
>"Jason" <XXXX@XXXXX.COM>writes
>news:43456c05$XXXX@XXXXX.COM...
>>Hello,
>>
>>I have a component that uses transparency, which means it can be
>>transparent
>>on top of an Image. It currently supports to be on top of an image. The
>>code
>>looks like:
>>
>>Canvas1.Draw(0, 0, Image1.Picture.Graphic);
>>
>>It reads the Image1.Picture.Graphic.
>>
>>There are two problems here.
>>
>>The component is actually 200x200 and the Image1 is 1024x768. So it
>>reads
>>more information that required.
>>And then when I want to use 2 images on the background, I cant do it :(
>>
>>Is there any good and fast way to screen capture a specific area lets
>>say
>>200x200 of my application? Including all things, Images, Labels etc? And
>>the
>>result to be TGraphic so I can use with the above code.
>>
>>Thanks
>>
>>
>>
>
>


 
 

Re: screen capture

Well all I need is some piece of code to grab a specific area of my form and
put it in TGraphics :(
Is that so difficult? I cant understand nobody did this in past?
"Jeremy Darling" <XXXX@XXXXX.COM>writes
Quote
Jason,
See if this is close to what you are trying to pull off:
www.eonclash.com/ViewProduct.php I wrote it quite a
few years ago, but the concepts still apply. It basically shows how to
get the transparancy so that controls under your control will show thru.
If its not what you need can you post a sample to B.P.A. If so I will take
a look at it and see what I can do.

Jeremy

"Jason" <XXXX@XXXXX.COM>writes
news:XXXX@XXXXX.COM...
>The component to put transparent needs to know what to put behind. So it
>has an Event "OnBackgroundDraw"
>
>and in their example: Canvas.Draw(0, 0, Image1.Picture.Graphic); //
>canvas is the component canvas
>
>It works fine, it put the image on the background and it makes the sense
>of transparency. But the problem is if I have more objects in the form?
>Labels, Edits etc they are disappear because the are not included in the
>Image1.Picture.Graphic. I need something bigger lets say
>Form1.Picture.Graphic but only the specific area, 200x200.
>
>Thanks
>
>
>"Jeremy Darling" <XXXX@XXXXX.COM>writes
>news:43458a67$XXXX@XXXXX.COM...
>>Jason,
>>What are you descending from for your component? If you are comming
>>down from TGraphicControl you can pull off transparency w/o having to
>>paint the background yourself.
>>
>>You can use the TCanvas.CopyMode property and TCanvas.CopyRect method
>>to retrieve only the area of the image that you need and place it onto
>>your canvas in the manor you wish. Their are also quite a few other
>>copy methods. The GDI and GDI+ API's also have different blt and bitblt
>>functions that can achieve what you are looking for.
>>
>>Post up a bit more info on what your trying to achieve :) and I am sure
>>someone will give you the answer that you need.
>>
>>Jeremy
>>
>>"Jason" <XXXX@XXXXX.COM>writes
>>news:43456c05$XXXX@XXXXX.COM...
>>>Hello,
>>>
>>>I have a component that uses transparency, which means it can be
>>>transparent
>>>on top of an Image. It currently supports to be on top of an image. The
>>>code
>>>looks like:
>>>
>>>Canvas1.Draw(0, 0, Image1.Picture.Graphic);
>>>
>>>It reads the Image1.Picture.Graphic.
>>>
>>>There are two problems here.
>>>
>>>The component is actually 200x200 and the Image1 is 1024x768. So it
>>>reads
>>>more information that required.
>>>And then when I want to use 2 images on the background, I cant do it :(
>>>
>>>Is there any good and fast way to screen capture a specific area lets
>>>say
>>>200x200 of my application? Including all things, Images, Labels etc?
>>>And the
>>>result to be TGraphic so I can use with the above code.
>>>
>>>Thanks
>>>
>>>
>>>
>>
>>
>
>


 

Re: screen capture

Well a quick search turns up:
delphi.about.com/od/internetintranet/l/aa012004a.htm <-- Witch points
to articles that talk about screen captures. Looking into the code we find
a method ScreenShot. Looking into this method we find that it retrieves the
Screen DC and uses that to capture a section of the (or the entire) screen.
This tells us that we can change to use our own DC GetWindowDC(form.handle)
(API reference) and then move the code that we need their. After the
modification we come up with:
procedure TForm1.ScreenShot(x : integer; y : integer; Width : integer;
Height : integer; bm : TBitMap);
var
dc: HDC; lpPal : PLOGPALETTE;
begin
{test width and height}
if ((Width = 0) OR (Height = 0)) then exit;
bm.Width := Width;
bm.Height := Height;
{get the screen dc}
dc := GetWindowDC(Form1.Handle);//replaced GetDc(0); witch pulls the
screen
if (dc = 0) then exit;
{do we have a palette device?}
if (GetDeviceCaps(dc, RASTERCAPS) AND RC_PALETTE = RC_PALETTE) then
begin
{allocate memory for a logical palette}
GetMem(lpPal, sizeof(TLOGPALETTE) + (255 * sizeof(TPALET{*word*249}TRY)));
{zero it out to be neat}
FillChar(lpPal^, sizeof(TLOGPALETTE) + (255 * sizeof(TPALET{*word*249}TRY)),
#0);
{fill in the palette version}
lpPal^.palVersion := $300;
{grab the system palette entries}
lpPal^.palNumEntries
:=GetSystemPalet{*word*249}tries(dc,0,256,lpPal^.palPalEntry);
if (lpPal^.PalNumEntries <>0) then
begin
{create the palette}
bm.Palette := CreatePalette(lpPal^);
end;
FreeMem(lpPal, sizeof(TLOGPALETTE) + (255 * sizeof(TPALET{*word*249}TRY)));
end;
{copy from the screen to the bitmap}
BitBlt(bm.Canvas.Handle,0,0,Width,Height,Dc,x,y,SRCCOPY);
{release the screen dc}
ReleaseDc(0, dc);
end; (* ScreenShot *)
That should get you started. BTW: I did answer the question that I thougth
you were asking for :). Just didn't understand you. The above code should
point you in the right direction or work straight out of the box. Haven't
tested it, but it makes sense.
One final note: The BitBlt function here (as I referenced in my first
reply) is the key, you can modify it to capture a small or the complete
section you want.
Jeremy
 

Re: screen capture

I am the author of the ScreenShot procedure you are using for the example.
Modified:
Quote
dc := GetWindowDC(Form1.Handle);//replaced GetDc(0); witch pulls the
As a long time writer of Windows graphics drivers (been writing them since Windows beta verison 0.8),
I had a pretty good reason for using the Screen's DC. The modification you made can break under some
circumstances.
Below you will find the tied and true original ScreenShot code, modified for later versions of the VCL that
support TBitmap.PixelFormat. Note that it is not dependent on Form1, and can be placed into a utility unit
and accessed from all of your projects.
procedure ScreenShot(x : integer;
y : integer;
Width : integer;
Height : integer;
bm : TBitMap);
var
dc: HDC;
lpPal : PLOGPALETTE;
begin
{test width and height}
if ((Width = 0) OR
(Height = 0)) then begin
exit;
end;
bm.Width := Width;
bm.Height := Height;
bm.PixelFormat := pfDevice;
{get the screen dc}
dc := GetDc(0);
if (dc = 0) then begin
exit;
end;
{do we have a palette device?}
if (GetDeviceCaps(dc, RASTERCAPS) AND
RC_PALETTE = RC_PALETTE) then begin
{allocate memory for a logical palette}
GetMem(lpPal,
sizeof(TLOGPALETTE) +
(255 * sizeof(TPALET{*word*249}TRY)));
{zero it out to be neat}
FillChar(lpPal^,
sizeof(TLOGPALETTE) +
(255 * sizeof(TPALET{*word*249}TRY)),
#0);
{fill in the palette version}
lpPal^.palVersion := $300;
{grab the system palette entries}
lpPal^.palNumEntries :=
GetSystemPalet{*word*249}tries(dc,
0,
256,
lpPal^.palPalEntry);
if (lpPal^.PalNumEntries <>0) then begin
{create the palette}
bm.Palette := CreatePalette(lpPal^);
end;
FreeMem(lpPal, sizeof(TLOGPALETTE) +
(255 * sizeof(TPALET{*word*249}TRY)));
end;
{copy from the screen to the bitmap}
BitBlt(bm.Canvas.Handle,
0,
0,
Width,
Height,
Dc,
x,
y,
SRCCOPY);
{release the screen dc}
ReleaseDc(0, dc);
end;
Joe
--
Delphi, graphics, and printing specialist available - $35/hr
www.code4sale.com/codeit/index.htm
Joe Hecht Associates
121 Louise Drive
Crestview, FL 32536
 

Re: screen capture

I am the author of the ScreenShot procedure you are using for the example.
Modified:
Quote
dc := GetWindowDC(Form1.Handle);//replaced GetDc(0); witch pulls the
As a long time writer of Windows graphics drivers (been writing them since Windows beta verison 0.8),
I had a pretty good reason for using the Screen's DC. The modification you made can break under some
circumstances.
Below you will find the tied and true original ScreenShot code, modified for later versions of the VCL that
support TBitmap.PixelFormat. Note that it is not dependent on Form1, and can be placed into a utility unit
and accessed from all of your projects.
procedure ScreenShot(x : integer;
y : integer;
Width : integer;
Height : integer;
bm : TBitMap);
var
dc: HDC;
lpPal : PLOGPALETTE;
begin
{test width and height}
if ((Width = 0) OR
(Height = 0)) then begin
exit;
end;
bm.Width := Width;
bm.Height := Height;
bm.PixelFormat := pfDevice;
{get the screen dc}
dc := GetDc(0);
if (dc = 0) then begin
exit;
end;
{do we have a palette device?}
if (GetDeviceCaps(dc, RASTERCAPS) AND
RC_PALETTE = RC_PALETTE) then begin
{allocate memory for a logical palette}
GetMem(lpPal,
sizeof(TLOGPALETTE) +
(255 * sizeof(TPALET{*word*249}TRY)));
{zero it out to be neat}
FillChar(lpPal^,
sizeof(TLOGPALETTE) +
(255 * sizeof(TPALET{*word*249}TRY)),
#0);
{fill in the palette version}
lpPal^.palVersion := $300;
{grab the system palette entries}
lpPal^.palNumEntries :=
GetSystemPalet{*word*249}tries(dc,
0,
256,
lpPal^.palPalEntry);
if (lpPal^.PalNumEntries <>0) then begin
{create the palette}
bm.Palette := CreatePalette(lpPal^);
end;
FreeMem(lpPal, sizeof(TLOGPALETTE) +
(255 * sizeof(TPALET{*word*249}TRY)));
end;
{copy from the screen to the bitmap}
BitBlt(bm.Canvas.Handle,
0,
0,
Width,
Height,
Dc,
x,
y,
SRCCOPY);
{release the screen dc}
ReleaseDc(0, dc);
end;
Joe
--
Delphi, graphics, and printing specialist available - $35/hr
www.code4sale.com/codeit/index.htm
Joe Hecht Associates
121 Louise Drive
Crestview, FL 32536
 

Re: screen capture

Interesting, odd that About had a different authors name listed.
Nice that you posted up the new code for everyone to make use of :). Think
I'll add this one to my own collection :).
Jeremy
"Joe C. Hecht" <XXXX@XXXXX.COM>writes
Quote
I am the author of the ScreenShot procedure you are using for the example.

Modified:
>dc := GetWindowDC(Form1.Handle);//replaced GetDc(0); witch pulls the

As a long time writer of Windows graphics drivers (been writing them since
Windows beta verison 0.8),
I had a pretty good reason for using the Screen's DC. The modification you
made can break under some
circumstances.

Below you will find the tied and true original ScreenShot code, modified
for later versions of the VCL that
support TBitmap.PixelFormat. Note that it is not dependent on Form1, and
can be placed into a utility unit
and accessed from all of your projects.

procedure ScreenShot(x : integer;
y : integer;
Width : integer;
Height : integer;
bm : TBitMap);
var
dc: HDC;
lpPal : PLOGPALETTE;
begin
{test width and height}
if ((Width = 0) OR
(Height = 0)) then begin
exit;
end;
bm.Width := Width;
bm.Height := Height;
bm.PixelFormat := pfDevice;
{get the screen dc}
dc := GetDc(0);
if (dc = 0) then begin
exit;
end;
{do we have a palette device?}
if (GetDeviceCaps(dc, RASTERCAPS) AND
RC_PALETTE = RC_PALETTE) then begin
{allocate memory for a logical palette}
GetMem(lpPal,
sizeof(TLOGPALETTE) +
(255 * sizeof(TPALET{*word*249}TRY)));
{zero it out to be neat}
FillChar(lpPal^,
sizeof(TLOGPALETTE) +
(255 * sizeof(TPALET{*word*249}TRY)),
#0);
{fill in the palette version}
lpPal^.palVersion := $300;
{grab the system palette entries}
lpPal^.palNumEntries :=
GetSystemPalet{*word*249}tries(dc,
0,
256,
lpPal^.palPalEntry);
if (lpPal^.PalNumEntries <>0) then begin
{create the palette}
bm.Palette := CreatePalette(lpPal^);
end;
FreeMem(lpPal, sizeof(TLOGPALETTE) +
(255 * sizeof(TPALET{*word*249}TRY)));
end;
{copy from the screen to the bitmap}
BitBlt(bm.Canvas.Handle,
0,
0,
Width,
Height,
Dc,
x,
y,
SRCCOPY);
{release the screen dc}
ReleaseDc(0, dc);
end;


Joe
--
Delphi, graphics, and printing specialist available - $35/hr
www.code4sale.com/codeit/index.htm
Joe Hecht Associates
121 Louise Drive
Crestview, FL 32536



 

Re: screen capture

Hello,
How do i capture all the windows on the screen (acrive and inactive) as an image? Please assist, i am new in the graphics area ;o)
 

Re: screen capture

"Zahir" <XXXX@XXXXX.COM>writes
Quote
How do i capture all the windows on the screen (acrive and inactive)
as an image? Please assist, i am new in the graphics area ;o)
Please go to www.deja.com and search through the newsgroup archives.
That question has been asked and answered many many times before, with
sample code posted.
Gambit