[Lazarus] How to save screenshot to jpg and png format files

Patrick Chevalley pch at ap-i.net
Thu Apr 29 18:49:06 CEST 2021


Hi,

Replace :
MyCapture.Bitmap.SaveToFile(ChangeFileExt(ParamStr(0), '.jpg'));
by :
MyCapture.SaveToFile(ChangeFileExt(ParamStr(0), '.jpg'));

This work because Bgrabitmap set automatically the image writer based on the extension. 

Patrick


29 avril 2021 17:49 "Bo Berglund via lazarus" <lazarus at lists.lazarus-ide.org> a écrit:

> I have an application which can capture a regon of the desktop into an image.
> It uses TBgraBitmap since it has a method for grabbing data from the screen.
> 
> So I can assign this to the clipboard and also save to a file:
> 
> var
> MyCapture : TBgraBitmap;
> Clip: TRect;
> ...
> begin
> ...
> Clip := Bounds(Self.Left, Self.Top, Self.Width, Self.Height);
> MyCapture := TBgraBitmap.Create();
> MyCapture.TakeScreenShot(Clip);
> Clipboard.Assign(MyCapture.Bitmap);
> MyCapture.Bitmap.SaveToFile(ChangeFileExt(ParamStr(0), '.jpg'));
> MyCapture.Free;
> ...
> end;
> 
> But the SaveToFile results in a file that is NOT a jpeg file at all...
> 
> How could I save it to a specific (known) format, like jpg or png?
> 
> -- 
> Bo Berglund
> Developer in Sweden
> 
> -- 
> _______________________________________________
> lazarus mailing list
> lazarus at lists.lazarus-ide.org
> https://lists.lazarus-ide.org/listinfo/lazarus


More information about the lazarus mailing list