使用TJpegImage组件将bmp转换为JPG [英] Problem converting bmp to jpg using TJpegImage Component

查看:201
本文介绍了使用TJpegImage组件将bmp转换为JPG的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个bmp文件,我试图把它转换成jpeg格式。使用以下代码创建的jpeg失去了很多的清晰度。我已经尝试调整许多设置无效。有没有人有一个将bmp文件转换成jpeg的功能?

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

Jpg.SaveToFile(JpgFileName);
finally
Jpg.Free;
Bmp.Free;
结束
结束

更新II 很多人都回应说jpeg不是图形在这种情况下使用的类型。理解不要打死一匹死马,但我已经能够使用其他程序(即Photoshop),并将其转换成一个漂亮的jpeg。我使用的工具来创建图表(fusioncharts)也可以将其导出为一个漂亮的jpeg(见下文)。有什么区别?

解决方案

正如其他人所说,JPEG只是错误的格式一种图像 - 与高频色度边缘,您可能是JPEG中最糟糕的图像之一!



我建议您获得一个 Paint.Net ,并尝试以不同格式(PNG,JPEG,GIF,BMP等)保存/预览图像,并获取感觉图像尺寸,质量和性能之间的权衡。



我已经尝试将Paint.net的测试图像保存为JPEG,并获得与Delphi完全一样的质量,因此您(或Delphi)正在做...



更新:
根据维基百科...


有一个可选的无损模式
定义在JPEG标准;然而,
这种模式在
产品中不被广泛支持。


我猜猜FusionCharts和Photoshop有一种方式来指定这种模式。它通常不被使用,因为JPEG通常被认为是LOSSY压缩的代名词。



总而言之,JPEG文件可以支持无损压缩,但JPEG不是理想的格式,因为它是没有得到广泛的支持。如果你想要无损,PNG仍然是一个更好的选择。您的图像的PNG压缩版本比无损压缩的JPEG格式(71K vs 101K)小30%。


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

Does anyone have a function which will convert a bmp file to a 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 A lot of people have responded that jpeg is not the graphic type to use in this case. Understood. Not to beat a dead horse, but I have been able to use other programs (i.e. Photoshop) and convert this to a nice looking jpeg. And the tool I am using to create the chart (fusioncharts) is able to export it to a nice looking jpeg too (see below). What is the difference?

解决方案

As others have said, JPEG is simply the wrong format for that kind of image - and with the high-frequency chroma edges, you have possibly one of the worst-case images for JPEG!

I recommend you get a copy of Paint.Net, and try saving/previewing images in different formats (PNG, JPEG, GIF, BMP, etc) and get a feel for the trade-offs between image size, quality and performance yourself.

I've tried saving your test image with Paint.net as JPEG, and get exactly the same quality as Delphi gives you, so there's nowt wrong with what you (or Delphi) are doing...

UPDATE: According to Wikipedia...

There is an optional lossless mode defined in the JPEG standard; however, that mode is not widely supported in products.

I'd guess that FusionCharts and Photoshop have a way of specifying this mode. It's not normally used, because JPEG is usually considered synonymous with LOSSY compression.

In summary, while JPEG files can support lossless compression, JPEG is not an ideal format to because it's not widely supported. If you want lossless, PNG remains a better choice. The PNG-compressed version of your image is 30% smaller than the losslessly compressed JPEG one (71K vs 101K)

这篇关于使用TJpegImage组件将bmp转换为JPG的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆