Ok, ich habe es mal versucht, es an meine Bedürfnisse anzupassen. Ich möchte also nur einen Screenhot vom kompletten Form meiner App. Mit der angehängten Prozedur klappt das nun fast, es fehlt leider die Statusbar. Die sollte doch eigentlich noch zum Form gehören. Auf den entstehenden Bilder fehlt sie aber, es ist vorher schon abgeschnitten. Wie kriege ich nun die Statusbar auch noch in den Screenshot?
Code: Alles auswählen
procedure TForm1.Button5Click(Sender: TObject);
var
MyBitmap: TBitmap;
MyBitmap2: TBitmap;
MyDC: HDC;
png: TPortableNetworkGraphic;
R: TRect;
begin
R.TopLeft := Form1.BoundsRect.TopLeft;
R.BottomRight := Form1.BoundsRect.BottomRight;
MyDC := GetDC(Self.Handle);
MyBitmap := TBitmap.Create;
MyBitmap2 := TBitmap.Create;
MyBitmap2.Width := R.Right - R.Left;
MyBitmap2.Height := R.Bottom - R.Top;
png := TPortableNetworkGraphic.Create;
try
MyBitmap.LoadFromDevice(MyDC);
MyBitmap.SaveToFile('FormsAppearance.bmp');
//MyBitmap2.Canvas.CopyRect(ClientRect,MyBitmap.Canvas,ClientRect);
MyBitmap2.Canvas.copyRect(Rect(0, 0, MyBitmap2.Width, MyBitmap2.Height),MyBitmap.Canvas, R);
MyBitmap2.SaveToFile('FormsAppearance2.bmp');
png.Assign(MyBitmap2);
png.SaveToFile('shottest.png');
finally
ReleaseDC(Self.Handle, MyDC);
FreeAndNil(MyBitmap);
FreeAndNil(MyBitmap2);
png.Free;
end;
end;