//==============================================================================
//转换JPG到BMP格式**************************************************************
//==============================================================================
procedure JPG2BMP(const Source, Target:string);
var JPG: TJpegImage;
    BMP: TBitmap;
begin
  BMP := TBitmap.Create;
  JPG := TJpegImage.Create;
  try
    JPG.LoadFromFile(Source);
    BMP.Assign(JPG);
    BMP.SaveToFile(Target);
  finally
    BMP.free;
    JPG.Free;
  end;
end;//==============================================================================
//转换BMP到JPG格式**************************************************************
//==============================================================================
procedure BMP2JPG(const Source, Target:string; const Scale: Byte);
var Image: TImage;
    JPG: TJpegImage;
begin
  Image := TImage.Create(Application);
  JPG := TJpegImage.Create;
  try
    Image.Picture.Bitmap.LoadFromFile(Source);
    JPG.Assign(Image.Picture.Bitmap);
    JPG.CompressionQuality := Scale;
    JPG.Compress;
    JPG.SaveToFile(Target);
  finally
    Image.free;
    JPG.Free;
  end;
end;

解决方案 »

  1.   

    确实要转换成GIF等其它格式不知如何写?
      

  2.   

    我也下了graphicEx 9.1,我是装上了的
     装的时候,不要全部都选上,看看说明!
     其中有4种语言包。
    我建议你其他3语言的包别装,只能4选1的!
     GraphicStringsRU.pas,GraphicStringsDE.pas,GraphicStringsFR.pas
    好象分别是俄语,德语,法语的支持包(我是这样理解的)
    Good luck!!!
      

  3.   

    可是说没有找到 jpg.pas 文件,怎么办呢?
      

  4.   

    shadou说的对,graphicex的帮助文档上已经写名安装时四选一,GraphicStrings就是英文语言包,其它三个是俄语什么的,不用装。jpg.pas找不到是因为在uses里没有引入jpeg单元。如果配上graphicex的话,可以把tif、eps、psd等等都装成jpg格式。
    我稍微改了一下quark的代码,可以转换各种格式到jpg。
    procedure Image2JPG(const Source, Target:string; const Scale: Byte);
    var Image: TImage;
        JPG: TJpegImage;
        GraphicClass: TGraphicExGraphicClass;
        Graphic: TGraphic;
    begin
      Image := TImage.Create(Application);
      JPG := TJpegImage.Create;
      try
          GraphicClass := FileFormatList.GraphicFromContent(Source);
          if GraphicClass = nil then
            Image.Picture.LoadFromFile(Source)
          else
          begin
            Graphic := GraphicClass.Create;
            Graphic.LoadFromFile(Source);
            Image.Picture.Graphic := Graphic;
          end;    JPG.Assign(Image.Picture.Graphic);
        JPG.CompressionQuality := Scale;
        JPG.Compress;
        JPG.SaveToFile(Target);
      finally
        Image.free;
        JPG.Free;
      end;
    end;