TBitmapCodecSaveParams XE5 problem

We have a product, based on Delphi XE5, Firemonkey in which we have to add a JPEG saving feature.  However the TBitmapCodecSaveParams quality setting has no effect on the saved outcome.  We do need the ability to control the quality of the compression.  It seems to work well with XE8 though but we can't risk moving the whole project to XE8 at this stage.  Is there any workaround for this problem?
0
Bennie
8/5/2015 6:46:06 PM
embarcadero.delphi.firemonkey 4901 articles. 4 followers. Follow

4 Replies
818 Views

Similar Articles

[PageSpeed] 44

Bennie wrote:

> We have a product, based on Delphi XE5, Firemonkey in which we have to
> add a JPEG saving feature.  However the TBitmapCodecSaveParams quality
> setting has no effect on the saved outcome.

Are you running your FMX app on Windows and saving the JPEG image to a TStream? 
 In XE3-XE5, the TBitmapCodecWIC.SaveToStream() method on Windows ignores 
the TBitmapCodecSaveParams.Quality value (that was fixed in XE6), but the 
TBitmapCodecWIC.SaveToFile() method does not ignore it.  Every other platform 
uses TBitmapCodecSaveParams.Quality for JPEG in their respective SaveToStream() 
and SaveToFile() implementations.

-- 
Remy Lebeau (TeamB)
0
Remy
8/5/2015 7:40:27 PM
> {quote:title=Remy Lebeau (TeamB) wrote:}{quote}
> Bennie wrote:
> 
> > We have a product, based on Delphi XE5, Firemonkey in which we have to
> > add a JPEG saving feature.  However the TBitmapCodecSaveParams quality
> > setting has no effect on the saved outcome.
> 
> Are you running your FMX app on Windows and saving the JPEG image to a TStream? 
>  In XE3-XE5, the TBitmapCodecWIC.SaveToStream() method on Windows ignores 
> the TBitmapCodecSaveParams.Quality value (that was fixed in XE6), but the 
> TBitmapCodecWIC.SaveToFile() method does not ignore it.  Every other platform 
> uses TBitmapCodecSaveParams.Quality for JPEG in their respective SaveToStream() 
> and SaveToFile() implementations.

Thank you for the reply.
Yes, this is at present a Windows FMX application which we may move over to other platforms.

We are using a very simple bitmap.savetofile(Filename, @CodecParams) instruction to save.

I am not sure what you mean by  TBitmapCodecWIC and cannot find it in the help either.  Am I missing something?
Regards
> 
> -- 
> Remy Lebeau (TeamB)
0
Bennie
8/6/2015 3:17:02 PM
Bennie wrote:

> We are using a very simple bitmap.savetofile(Filename, @CodecParams)
> instruction to save.

Then it should be working, as Bitmap.SaveToFile() implements Quality, it 
is only Bitmap.SaveToStream() that does not implement Quality on Windows.

> I am not sure what you mean by  TBitmapCodecWIC

That is the underlying class that TBitmap uses internally on Windows to stream 
its data to/from files and streams.

> and cannot find it in the help either.

No, because it is an internal implementation class, not for public use.

-- 
Remy Lebeau (TeamB)
0
Remy
8/7/2015 4:52:01 PM
> {quote:title=Remy Lebeau (TeamB) wrote:}{quote}
> Bennie wrote:
> 
> > We are using a very simple bitmap.savetofile(Filename, @CodecParams)
> > instruction to save.
> 
> Then it should be working, as Bitmap.SaveToFile() implements Quality, it 
> is only Bitmap.SaveToStream() that does not implement Quality on Windows.
> 

Thanks for the answer.  I do however still have the problem.  I am attaching my test program which, when run in XE5 produces results of exactly the same size inamges and under XE8 the size (and quality) reduces as expected.  Maybe I am using it incorrectly so assistance will be appreciated.
{code}
unit uTestCODEC;

interface

uses
  System.SysUtils, System.Types, System.UITypes, System.Classes, System.Variants,
  FMX.Types, FMX.Graphics, FMX.Controls, FMX.Forms, FMX.Dialogs, FMX.StdCtrls,
  FMX.Objects;

type
  TForm1 = class(TForm)
    Image1: TImage;
    btn100: TButton;
    btn80: TButton;
    btn60: TButton;
    btn50: TButton;
    btn30: TButton;
    btn20: TButton;
    btn10: TButton;
    procedure FormShow(Sender: TObject);
    procedure btn100Click(Sender: TObject);
    procedure btn80Click(Sender: TObject);
    procedure btn60Click(Sender: TObject);
    procedure btn50Click(Sender: TObject);
    procedure btn30Click(Sender: TObject);
    procedure btn20Click(Sender: TObject);
    procedure btn10Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.fmx}

var
  CodecParams: TBitmapCodecSaveParams;

procedure TForm1.btn10Click(Sender: TObject);
begin
  CodecParams.Quality := 10;
  Image1.bitmap.SaveToFile('..\..\i10.jpg', @CodecParams);
end;

procedure TForm1.btn20Click(Sender: TObject);
begin
  CodecParams.Quality := 20;
  Image1.bitmap.SaveToFile('..\..\i20.jpg', @CodecParams);
end;

procedure TForm1.btn30Click(Sender: TObject);
begin
  CodecParams.Quality := 30;
  Image1.bitmap.SaveToFile('..\..\i30.jpg', @CodecParams);
end;

procedure TForm1.btn50Click(Sender: TObject);
begin
  CodecParams.Quality := 50;
  Image1.bitmap.SaveToFile('..\..\i50.jpg', @CodecParams);
end;

procedure TForm1.btn60Click(Sender: TObject);
begin
  CodecParams.Quality := 60;
  Image1.bitmap.SaveToFile('..\..\i60.jpg', @CodecParams);
end;

procedure TForm1.btn80Click(Sender: TObject);
begin
  CodecParams.Quality := 80;
  Image1.bitmap.SaveToFile('..\..\i80.jpg', @CodecParams);
end;

procedure TForm1.btn100Click(Sender: TObject);
begin
  CodecParams.Quality := 100;
  Image1.bitmap.SaveToFile('..\..\i100.jpg', @CodecParams);
end;

procedure TForm1.FormShow(Sender: TObject);
begin
  Image1.Bitmap.LoadFromFile('..\..\6X8A8772.jpg');
end;

end.
{code}
0
Bennie
8/11/2015 5:33:29 PM
Reply: