Creating jpg to specific sizes

TeeChart VCL for Borland/CodeGear/Embarcadero RAD Studio, Delphi and C++ Builder.
Post Reply
Benny
Newbie
Newbie
Posts: 6
Joined: Thu Aug 05, 2010 12:00 am

Creating jpg to specific sizes

Post by Benny » Mon May 09, 2011 8:46 pm

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.

Sandra
Site Admin
Site Admin
Posts: 3132
Joined: Fri Nov 07, 2008 12:00 am

Re: Creating jpg to specific sizes

Post by Sandra » Wed May 11, 2011 1:19 pm

Hello Benny,

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

Thanks,
Best Regards,
Sandra Pazos / Development & Support
Steema Software
Avinguda Montilivi 33, 17003 Girona, Catalonia
Tel: 34 972 218 797
http://www.steema.com
Image Image Image Image Image Image
Instructions - How to post in this forum

Benny
Newbie
Newbie
Posts: 6
Joined: Thu Aug 05, 2010 12:00 am

Re: Creating jpg to specific sizes

Post by Benny » Wed May 11, 2011 9:39 pm

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!

Narcís
Site Admin
Site Admin
Posts: 14730
Joined: Mon Jun 09, 2003 4:00 am
Location: Banyoles, Catalonia
Contact:

Re: Creating jpg to specific sizes

Post by Narcís » Fri May 13, 2011 11:01 am

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.
Best Regards,
Narcís Calvet / Development & Support
Steema Software
Avinguda Montilivi 33, 17003 Girona, Catalonia
Tel: 34 972 218 797
http://www.steema.com
Image Image Image Image Image Image
Instructions - How to post in this forum

Benny
Newbie
Newbie
Posts: 6
Joined: Thu Aug 05, 2010 12:00 am

Re: Creating jpg to specific sizes

Post by Benny » Tue Jun 07, 2011 12:53 pm

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!

Benny
Newbie
Newbie
Posts: 6
Joined: Thu Aug 05, 2010 12:00 am

Re: Creating jpg to specific sizes

Post by Benny » Tue Jun 07, 2011 5:55 pm

A quick question, will the bug you mentioned be a fix in the new release?

Sandra
Site Admin
Site Admin
Posts: 3132
Joined: Fri Nov 07, 2008 12:00 am

Re: Creating jpg to specific sizes

Post by Sandra » Wed Jun 08, 2011 11:33 am

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,
Best Regards,
Sandra Pazos / Development & Support
Steema Software
Avinguda Montilivi 33, 17003 Girona, Catalonia
Tel: 34 972 218 797
http://www.steema.com
Image Image Image Image Image Image
Instructions - How to post in this forum

Post Reply