Page 1 of 1

Creating jpg to specific sizes

Posted: Mon May 09, 2011 8:46 pm
by 16456689
Please excuse if this has been covered, but I can't find it specifically in the forums...

The following procedure works great. But everytime you run it, it takes .1 seconds longer. So after 50 times, it will add 5 seconds to the time and we can't afford this kind of mark-up when running hundreds of files.

TeeSaveToJPEGFile(AliasChart,WebServerFolder+GraphHTMLJpegLink1FileName,False,jpBestSpeed, 60,800,400,200);

Here is a solution that we saw on this site:
tmp:= TJPEGExportFormat.Create;
tmp.Panel:=AliasChart;
tmp.SaveToFile(WebServerFolder+GraphHTMLJpegLink1FileName);
tmp.free;

What we need to figure out is how do we give the options of
60% compression,
800 pixel width
400 pixel height
200 DPI
without having an Option dialog box as the user. We want to program these "Export Options" into the command.

Any help would be wonderful, thanks! I'm using VCL 2010 version.

Re: Creating jpg to specific sizes

Posted: Wed May 11, 2011 1:19 pm
by 10050769
Hello Benny,

Sorry for the delay.Could you arrange for us a simple project so we can reproduce exactly your problem?

Thanks,

Re: Creating jpg to specific sizes

Posted: Wed May 11, 2011 9:39 pm
by 16456689
We are currently on a time crunch at the moment, but as soon as I get a chance I'll create a small project to show you exactly what we mean...
Thanks for your response!

Re: Creating jpg to specific sizes

Posted: Fri May 13, 2011 11:01 am
by narcis
Hi Benny,

I have run some test here using code below. I found that using TeeSaveToJPEGFile time slightly increases every time Button1Click is executed. It's also a little bit slower than TJPEGExportFormat in Button2Click which also remains more stable after several executions. Is that behavior what you experienced at your end? Does code in Button2Click solves the problem for you?

Code: Select all

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, ExtCtrls, TeeProcs, TeEngine, Chart, ComCtrls;

type
  TForm1 = class(TForm)
    Chart1: TChart;
    Button1: TButton;
    Button2: TButton;
    procedure Button1Click(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure Button2Click(Sender: TObject);
  private
    { Private declarations }
    procedure StartTimer;
    procedure StopTimer;
  public
    { Public declarations }
    StartTime: TDateTime;
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

uses Series, TeeJPEG, TeeExport, jpeg;

procedure TForm1.FormCreate(Sender: TObject);
begin
  Chart1.AddSeries(TLineSeries.Create(Self)).FillSampleValues;
end;

procedure TForm1.Button1Click(Sender: TObject);
var i: Integer;
begin
  StartTimer;

  for i:=1 to 50 do
    TeeSaveToJPEGFile(Chart1,'chart' + IntToStr(i) + '.jpg', False,
                    jpBestSpeed, 60, 800, 400, 200);

  StopTimer;
end;

procedure TForm1.Button2Click(Sender: TObject);
var i: Integer;
    Stream: TMemoryStream;
begin
  StartTimer;

  for i:=1 to 50 do
    with TJPEGExportFormat.Create do
    begin
      Panel:=Chart1;
      Quality:=60;
      Width:=800;
      Height:=400;
      Stream:=TMemoryStream.Create;
      SaveToStream(Stream);
      Stream.Position:=0;
      SetDpiJPEG(Stream, 200, 200);
      Stream.SaveToFile('chart' + IntToStr(i) + '.jpg');
      Free;
      Stream.Free;
    end;

  StopTimer;
end;

procedure TForm1.StartTimer;
begin
  StartTime:=Now;
end;

procedure TForm1.StopTimer;
var TimeSpan: TDateTime;
begin
  TimeSpan:=Now-StartTime;
  Caption:=FormatDateTime('hh:mm:ss:zzz', TimeSpan);
end;
Thanks in advance.

Re: Creating jpg to specific sizes

Posted: Tue Jun 07, 2011 12:53 pm
by 16456689
Thanks for the reply, I was able to use snippets of your code to accomplish my tasks.
However, when I use the code just as you wrote it, the processing time increases .1 seconds every time we run the procedure.
We run this procedure 18 times per each user logging in, so .1 = 1.8 seconds delay each time we run it.
The streaming part of the code seems to add time to the code.
Thanks again for your help!

Re: Creating jpg to specific sizes

Posted: Tue Jun 07, 2011 5:55 pm
by 16456689
A quick question, will the bug you mentioned be a fix in the new release?

Re: Creating jpg to specific sizes

Posted: Wed Jun 08, 2011 11:33 am
by 10050769
Hello Benny,

The bug is added in bug list report with number [TV52015605]. We try to fix it for next maintenance releases of TeeChartVCL.I recommend you to be aware at this forum, our RSS news feed, twitter and facebook accounts for new release announcements and what's implemented on them.

Thanks,