Delphi-PRAXiS
Seite 2 von 2     12   

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Programmieren allgemein (https://www.delphipraxis.net/40-programmieren-allgemein/)
-   -   Screenshot und Skalierung (https://www.delphipraxis.net/216205-screenshot-und-skalierung.html)

DeddyH 20. Nov 2024 09:59

AW: Screenshot und Skalierung
 
Hier ist es noch einmal erklärt: https://stackoverflow.com/questions/...xternal-window

tofse01 25. Nov 2024 08:37

AW: Screenshot und Skalierung
 
Liste der Anhänge anzeigen (Anzahl: 1)
Hallo
ich komme erst jetzt wieder dazu, mich damit zu beschäftigen, deshalb erst heute meine Rückmeldung
Ich stehe total auf dem Schlauch, auch in Bezug auf diese Antwort. Wieso startet das bei 0,0 ?

Ich habe nochmal ein Bild angehängt worum es mir geht.
Es gibt eine beliebige Anwendung, Position der Anwendung ist variabel. Ich benötige einen Screenshot dieser Anwendung. Handle der Anwendung hab ich.

Ich erstelle also einen Screenshot vom kompletten Desktop, wie im Anhang zu sehen. Über das Handle bekomme ich die Koordinaten des Fenster der anderen Anwendung, hier im Beispiel 45 x 160. Das ist ja nicht 0 x 0
Die anderen Koordinaten habe ich ja auch. Ich muss also aus dem kompletten Screenshot den rot markierten Bereich rauskopieren. Wenn ich die Skalierung auf 100% hab, funktioniert es, wenn die Skalierung windowsseitig bei 125% ist, ist alles verschoben und die Maße passen nicht



Zitat:

Zitat von supermulti81 (Beitrag 1543306)
Oben links brauchst du doch gar nicht.

du holst doch das Bild über das Handle und das startet bei x=0 und y=0.
und GetClientRect(hWindow, R);
gibt dir ein Rect zurück. Da verwendest du Width und Height.

Width := R.Width;
Height := R.Height;

und bitte noch setzen:
Left := 0;
Top := 0;

dann klappt auch dein BitBlt.

BitBlt(bm.Canvas.Handle,
0,
0,
Width,
Height,
Dc,
Left,
Top,
SRCCOPY);


tofse01 25. Nov 2024 10:30

AW: Screenshot und Skalierung
 
Was ich erst jetzt verstanden hab, ich kann auch einen SCreenshot vom aktiven Fenster machen und muss gar nicht "rauskopieren"
Habe diese Funktion nun im Einsatz

Das Problem mit der Skalierung bleibt aber, habe dann bei dem rot markierten Code das ganze noch so berücksichtigt. Damit scheint es nun zu funktionieren

iWidth := round((Rec.Right - Rec.Left)*1.25);
iHeight := round((Rec.Bottom - Rec.Top)*1.25);


Delphi-Quellcode:
function FormularSaveScreenShot(FileName: String; h : hWnd): Boolean;
var
  Rec: TRect;
  iWidth, iHeight: Integer;
begin
  with TBitmap.Create do try
    GetWindowRect(h, Rec);

    iWidth := round((Rec.Right - Rec.Left)*1.25);
    iHeight := round((Rec.Bottom - Rec.Top)*1.25);

    Width := iWidth;
    Height := iHeight;

    BitBlt(Canvas.Handle, 0, 0, iWidth, iHeight, GetWindowDC(h), 0, 0, SRCCOPY);

    Result := True;

    try SaveToFile(Filename) except Result := False end;
  finally
    ReleaseDC(h, GetWindowDC(h));
    Free;
  end;
end;

Kas Ob. 25. Nov 2024 11:12

AW: Screenshot und Skalierung
 
@tofse01 , do yourself a favor and drop using this half baked approach by copying DC, because this will always have problems unless it get way more complicated, a complexity which very needed here to do it right.

See, you are creating a DC then copying from the target application DC, did you queried the target DC scaling ? no you did not, to be done right this way you should align the DC in parameters (dimensions, color, device capability and of course scaling ), here comes the OS forced values and the target application if it is following the OS request or is doing it by its own custom drawing, example AlphaSkins does the scaling on its own (only if configured to do that or just leave it the OS).

Anyway, drop that approach and ask the target application to to the drawing for you ! this is simpler and will work exactly as intended no matter what OS is doing.

Please take a look at the answer here https://stackoverflow.com/questions/...ap-object-in-c

And use PrintWindow, or even the better approach with SendMessage of WM_PRINTCLIENT or WM_PRINT ..
https://learn.microsoft.com/en-us/wi...wm-printclient

Kas Ob. 25. Nov 2024 11:14

AW: Screenshot und Skalierung
 
One more thing, with these Print function/messages the target will be drawn even if it is behind other windows, so you are not screenshot the desktop (as your code now), no, you are drawing the application as it would be if it is focused and on top.


Alle Zeitangaben in WEZ +1. Es ist jetzt 19:27 Uhr.
Seite 2 von 2     12   

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024-2025 by Thomas Breitkreuz