Registriert seit: 25. Apr 2006
131 Beiträge
Turbo Delphi für Win32
|
Re: Screenshot via Handle
22. Jun 2008, 22:21
mein Problem ist nicht die Berechnung, die funktioniert perfekt. Es muss irgendwas mit den Handles zu tun habe, da ich exakt die gleiche Funktion verwende um einen Screenshot vom kompletten Desktop auszuwerten, also GetDC
hier mal eine aktualisierte Version, die aber nach wie vor, das Problem des Speicherverbrauchs hat
Delphi-Quellcode:
procedure HandleToPix(h_handle: HWND);
var
i_tmp_x, i_tmp_y: Integer;
i_gesRed, i_gesGreen, i_gesBlue: Integer;
bRed, bGreen, bBlue: Byte;
c_tmp: TCanvas;
c_color: TColor;
r_window: TRect;
i_width, i_height: Integer;
p_window: ^HWND;
const
c_aspectorato = (4/3);
//c_aspectorato = (16/9);
c_vertical = 7;
begin
c_tmp := TCanvas.Create;
p_window := @h_handle;
try
c_tmp.Handle := GetWindowDC(p_window^);
//c_tmp.Handle := GetDC(p_window^);
GetWindowRect(p_window^, r_window);
i_width := r_window.Right - r_window.Left;
i_height := r_window.Bottom - r_window.Top;
//c_tmp.BrushCopy(Rect(0,0,i_width, i_height), GetWindowDC(h_handle), Rect(0,0,i_width, i_height));
BitBlt(c_tmp.Handle, 0, 0, i_width, i_height, GetWindowDC(h_handle), 0, 0, SRCCOPY);
i_gesBlue := 0;
i_gesGreen := 0;
i_gesRed := 0;
for i_tmp_x := 1 to round(c_aspectorato*c_vertical) do
begin
for i_tmp_y := 1 to c_vertical do
begin
c_color := c_tmp.Pixels[round((i_width / (c_aspectorato*c_vertical))*i_tmp_x), round((i_height/c_vertical)*i_tmp_y)];
bBlue := GetBValue(c_color);
bGreen := GetGValue(c_color);
bRed := GetRValue(c_color);
rgb_threshold(bRed, bGreen, bBlue);
i_gesBlue := i_gesBlue + bBlue;
i_gesGreen := i_gesGreen + bGreen;
i_gesRed := i_gesRed + bRed;
end;
end;
//Werte ausgeben
changeRGB(Round(i_gesRed / (round(c_aspectorato*c_vertical)*c_vertical)),
Round(i_gesGreen / (round(c_aspectorato*c_vertical)*c_vertical)),
Round(i_gesBlue / (round(c_aspectorato*c_vertical)*c_vertical)));
finally
ReleaseDC(p_window^, c_tmp.Handle);
freeandnil(c_tmp);
end;
//BitBlt(c_tmp.Handle, 0, 0, b_tmp.Width, b_tmp.Height, GetWindowDC(h_window), 0, 0, SRCCOPY);
//BitBlt(c_tmp.Handle, 0, 0, i_width, i_height, GetWindowDC(h_window), 0, 0, SRCCOPY);
end;
|