function Bmp2Jpg(Bmp: TBitmap; Quality: Integer = 100): TJpegImage; begin   Result := nil;   if Assigned(Bmp)   then begin   Result := TJpegImage.Create;   Result.Assign(Bmp); {Its all folks...}   Result.CompressionQuality := Quality;   Result.JPEGNeeded; {Key method...}   Result.Compress;   end;end; function Jpg2Bmp(Jpg: TJpegImage): TBitmap; begin   Result := nil;   if Assigned(Jpg)   then begin   Result := TBitmap.Create;   Jpg.DIBNeeded; {Key method...}   Result.Assign(Jpg); {Its all folks...}   end; end;

解决方案 »

  1.   

    //==============================================================================
    //转换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;