Autor Beitrag
JustusJonas
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 222



BeitragVerfasst: Mo 18.09.06 15:53 
Hallo Leute,

mit folgender Funktion mache ich einen Screenshot:

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
procedure TForm1.ScreenCapture(Bmp: TBitmap; Oben, Links, Hoehe, Breite: Integer);
var
  DeskWnd: HWnd;
  DeskDC: HDC;
  DeskCv: TCanvas;
  R: TRect;
  W, H: Integer;
begin
  if Bmp = nil then Exit;
  DeskWnd := GetDesktopWindow;
  DeskDC := GetWindowDC(DeskWnd);
  DeskCv := TCanvas.Create;
  DeskCv.Handle := DeskDC;
  W := Breite;
  H := Hoehe;
  R := Bounds(Links, Oben, W, H);
  try
    Bmp.HandleType := bmDIB;
    Bmp.PixelFormat := pf24Bit;
    Bmp.Width := W;
    Bmp.Height := H;
    Bmp.Canvas.CopyMode := cmSrcCopy;
    Bmp.Canvas.CopyRect(R, DeskCv, R);
  finally
    DeskCv.Free;
    ReleaseDC(DeskWnd, DeskDC);
  end;
end;


Das funktioniert auch ganz gut, wenn "Oben" und "Links" = 0 ist und "Hoehe" und "Breite" die gesamte Bildschirmgröße.

Ich möchte aber auch gerne Screenshots von nur einem ausgewählten Bereich machen.
Dazu öffne ich eine Form2. Diese kann in Größe und Position geändert werden. Wird diese geschlossen, werden die Werte "Oben", "Links", "Hoehe" und "Breite" der Form2 in meine Edit-Felder gespeichert.

So rufe ich die Screenshotfunktion auf:
ausblenden Delphi-Quelltext
1:
2:
ScreenCapture(Bmp, StrToInt(edtX.Text), StrToInt(edtY.Text), StrToInt(edtHeight.Text), StrToInt(edtWidth.Text));
  Bmp2Jpg(BMP, 100, sFileName);


Wie gesagt, den kompletten Screen funktioniert einwandfrei.
Mein Problem ist, dass die Screenshots vom ausgewählten Bereich zwar erstellt werden (auch in der angegebenen Größe), aber dass die Bilder einfach nur weiß sind. Hat jemand eine Idee was das sein könnte?

Greetz
huhn
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 272
Erhaltene Danke: 1

WIN XP
D7Pers
BeitragVerfasst: Mo 18.09.06 16:38 
sorry ausversehen im thread verrutscht xD
//edit:versuch des mal
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
procedure MakeScreenShot(x,y,h,b:integer;var result:TBitmap);
var
  DesktopDC: HDC;
begin
  DesktopDC := GetDC(0);
  try
    result.width:=b;
    result.height:=h;
  
    BitBlt(Result.Canvas.Handle, 00, b, h, DesktopDC, x, y, SRCCOPY);
  finally
    DeleteDC(DesktopDC);
  end;
end;

Beispiel:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
procedure TForm1.Button3Click(Sender: TObject);
var
  DesktopDC: HDC;
  b:TBitmap;
begin
  if not SD.Execute then exit;
  DesktopDC := GetDC(0);
  b:=TBitmap.Create;
  try
    b.width:=100;
    b.height:=100;

    BitBlt(b.Canvas.Handle,00100100, DesktopDC, 1010, SRCCOPY);
  finally
    DeleteDC(DesktopDC);
  end;
  b.SaveToFile(SD.FileName+'.bmp');
  b.Free;
end;

_________________
Quod Erat Demonstrandum-Was zu beweisen war! *THX to Chrissivo!*


Zuletzt bearbeitet von huhn am Mo 18.09.06 16:58, insgesamt 3-mal bearbeitet
JustusJonas Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 222



BeitragVerfasst: Mo 18.09.06 16:41 
Ich check überhaupt nix....was willst du mir damit sagen?

Greetz
JustusJonas Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 222



BeitragVerfasst: Mi 20.09.06 09:56 
OK, du warst schneller mit editieren ;)

Dankeschön, so hats funktioniert!

Greetz