Mega Code Archive

 
Categories / Delphi / Graphic
 

Convert a Bitmap to a JPEG and save it

Title: convert a Bitmap to a JPEG and save it? uses Jpeg, ClipBrd; procedure TfrmMain.ConvertBMP2JPEG; // konvertiert ein Bitmap, z.B. die Grafik eines TCharts in ein JPEG // converts a bitmap, the graphic of a TChart for example, to a jpeg var jpgImg: TJPEGImage; begin // copy bitmap to clipboard chrtOutputSingle.CopyToClipboardBitmap; // get clipboard and load it to Image1 Image1.Picture.Bitmap.LoadFromClipboardFormat(cf_BitMap, ClipBoard.GetAsHandle(cf_Bitmap), 0); // create the jpeg-graphic jpgImg := TJPEGImage.Create; // assign the bitmap to the jpeg, this converts the bitmap jpgImg.Assign(Image1.Picture.Bitmap); // and save it to file jpgImg.SaveToFile('TChartExample.jpg'); end;