3

I use the procedure below to create a JPG file from a TWebbrowser That is resulting in a JPG looking OK Then I load this JPG to a TcxImage control from DevExpress in order to print it. And that messes up my image so it isn't possible to see the map (it is a portion of a map from Google Maps) The code for loading the image is

imgPrint.Picture.LoadFromFile(lImage);

I don't quite get why this is looking so bad already on screen. I do it this way in order to be able to print the map. It could also be done direct from the TWebBrowser but ther I have no control of the output size and adding my own headers and footers are tricky.

procedure TfrmJsZipExplorer.actSaveExecute(Sender: TObject);
var
  ViewObject : IViewObject;
  r : TRect;
  Bitmap: TBitmap;
begin
  if WebBrowser1.Document <> nil then
    begin
      WebBrowser1.Document.QueryInterface(IViewObject, ViewObject) ;
      if Assigned(ViewObject) then
        try
          Bitmap := TBitmap.Create;
          try
            r := Rect(0, 0, WebBrowser1.Width, WebBrowser1.Height) ;
            Bitmap.Height := WebBrowser1.Height;
            Bitmap.Width := WebBrowser1.Width;
            ViewObject.Draw(DVASPECT_CONTENT, 1, nil, nil, Application.Handle, bitmap.Canvas.Handle, @r, nil, nil, 0);
            with TJPEGImage.Create do
              try
                Assign(Bitmap);
                SaveToFile(lImagefile);
              finally
                Free;
            end;
          finally
            Bitmap.Free;
          end;
        finally
          ViewObject._Release;
        end;
    end;
end;
4

1 回答 1

4

如何提高保存的 JPEG 图像质量?

您可以将CompressionQuality保存图像的属性设置为最低压缩,但最高图像质量值。这将提高输出图像的视觉质量。将此属性设置为 100 将产生更好的图像质量,但文件大小更大:

with TJPEGImage.Create do
try
  Assign(Bitmap);      
  CompressionQuality := 100;
  SaveToFile(lImagefile);
finally
  Free;
end;

此图像存档是否需要使用 JPEG 格式?

如果您的图像存档不仅限于 JPEG 格式,请考虑使用其他格式,例如 PNG。如果您决定使用带TPNGImage类的 PNG 格式,则有一个CompressionLevel属性,它允许您指定保存图像的压缩级别,它直接影响输出文件的大小,但与 JPEG 格式压缩不同,它保持相同视觉质量。将此属性设置为 9 将导致使用完全压缩,这会产生更小的文件大小,质量保持与不使用压缩(0 值)相同:

uses
  PNGImage;

with TPNGImage.Create do
try
  Assign(Bitmap);
  CompressionLevel := 9;
  SaveToFile(lImagefile);
finally
  Free;
end;
于 2013-02-02T11:20:54.947 回答