Converting bmp to jpg using TJpegImage component

I have a bmp file and am trying to convert it to jpeg format. A jpeg created using the following code loses a lot of clarity. I tried to configure many settings to no avail.

Does anyone have a function that converts a BMP file to jpeg?

var
  Bmp: TBitmap;
  Jpg: TJPEGImage;
begin
  Bmp := TBitmap.Create;
  Jpg := TJPEGImage.Create;
  try
    Bmp.LoadFromFile(BmpFileName);
    Jpg.Assign(Bmp);
    jpg.PixelFormat    :=jf24bit;  // or jf8bit
    Jpg.CompressionQuality := 100;
    Jpg.ProgressiveDisplay := False;
    Jpg.ProgressiveEncoding := False;

    Jpg.SaveToFile(JpgFileName);
  finally
    Jpg.Free;
    Bmp.Free;
  end;
end;

Update II . Many people answered that jpeg is not a graphical type to use in this case. I get it. Not to beat a dead horse, but I was able to use other programs (i.e. Photoshop) and convert this to a beautiful gpeg. And the tool that I use to create the chart (fusioncharts) can also export it to a pretty jpeg (see below). What is the difference?

+5
5

, JPEG - - , , JPEG!

Paint.Net / (PNG, JPEG, GIF, BMP ..), , .

Paint.net JPEG , Delphi, , ( Delphi)...

UPDATE: ...

JPEG; , .

, FusionCharts Photoshop . , JPEG LOSSY.

, JPEG , JPEG , . , PNG . PNG- 30% , JPEG (71K 101K)

+1

, , .. CompressionQuality := 100.

JPG . JPG . ( > ~ 80), , ..

JPG , . , , .., , .., JPG. PNG. PNG (, !), .

, , JPG ! PNG!

+4

, . .

1) TsdJpegGraphic NativeJPG Delphi TJPEGImage. .

2) :

var
  Bmp: TBitmap;
  Jpg: TsdJpegGraphic;
begin
  Bmp := TBitmap.Create;
  Jpg := TsdJpegGraphic.Create;
  try
    Bmp.LoadFromFile(BmpFileName);
    Jpg.CompressionQuality := 100; // !!!
    Jpg.Assign(Bmp);
    Jpg.SaveToFile(JpgFileName);
  finally
    Jpg.Free;
    Bmp.Free;
  end;
end;

CompressionQuality, Jpg! , (= 80%) CompressionQuality.

+2

, jpg.CompressionQuality. jpg.Compress(), ...

- :

jpg: = TJPEGImage.Create(); jpg.LoadFromFile( 'foo.jpg'); jpg.DIBNeeded(); jpg.CompressionQuality: = 25; jpg.Compress(); jpg.SaveToFile( 'bar.jpg'); jpg.Free();

,

0

All Articles