Einzelnen Beitrag anzeigen

Benutzerbild von Zacherl
Zacherl

Registriert seit: 3. Sep 2004
4.629 Beiträge
 
Delphi 10.2 Tokyo Starter
 
#1

Wie Bitmap per API erstellen und speichern

  Alt 17. Jun 2010, 22:06
Hey,

ich habe eine Funktion, mit der ich einen Screenshot des kompletten Desktops erstellen kann:
Delphi-Quellcode:
procedure TScreenCaptureThread.CreateBitmapScreenShot(Bitmap: TBitmap;
  Format: TPixelFormat; Ratio: TResolutionRatio);
var
  C: TCanvas;
  R: TRect;
  Width, Height: Integer;
  B: TBitmap;
begin
  C := TCanvas.Create;
  C.Handle := GetWindowDC(GetDesktopWindow);
  try
    Width := GetSystemMetrics(SM_CXSCREEN);
    Height := GetSystemMetrics(SM_CYSCREEN);
    R := Rect(0, 0, Width, Height);
    if (Ratio = 100) then
    begin
      Bitmap.Width := Width;
      Bitmap.Height := Height;
      Bitmap.PixelFormat := Format;
      Bitmap.Canvas.CopyRect(R, C, R);
    end else
    begin
      B := TBitmap.Create;
      try
        B.Width := Width;
        B.Height := Height;
        B.PixelFormat := Format;
        B.Canvas.CopyRect(R, C, R);
        Bitmap.Width := Round(Width * 0.01 * Ratio);
        Bitmap.Height := Round(Height * 0.01 * Ratio);
        Bitmap.PixelFormat := Format;
        Bitmap.Canvas.StretchDraw(Rect(0, 0, Bitmap.Width, Bitmap.Height), B);
      finally
        B.Free;
      end;
    end;
  finally
    ReleaseDC(0, C.Handle);
    C.Free;
  end;
end;
Jetzt will ich allerdings gerne auf die Graphics.pas Unit verzichten und kann daher auch nicht mehr die Klassen TCanvas und TBitmap verwenden. Meine Frage jezt:
Welche Windows APIs benötige ich, um die Screenshot Funktion ohne die Delphi RTL nachzubilden?
Und ganz wichtig: Wie kann ich das so erstellte Bitmap dann in einer Datei oder einem Buffer speichern?

Viele Grüße
Zacherl
  Mit Zitat antworten Zitat