TeeCreateBitmap Memory Problem - TChart

TeeChart VCL for Borland/CodeGear/Embarcadero RAD Studio, Delphi and C++ Builder.
Post Reply
Steve Chamberlain
Newbie
Newbie
Posts: 15
Joined: Mon Nov 20, 2006 12:00 am
Location: The Netherlands
Contact:

TeeCreateBitmap Memory Problem - TChart

Post by Steve Chamberlain » Wed Dec 19, 2007 11:16 am

Hi All,

I have a problem printing TChart objects. Here is my situation:

I have a C++ project in Borland Developer Studio which uses TCharts. These charts TeeCreateBitmap method is called to extract a bitmap object which is stored in a database for use in Crystal Reports.

The chart szies are very large (3000 x 3000), so that text and and font are in the right proportion.

Image
This is what is expected

However, in some cases this causes an EOutOfResources occurs as these images are so large, in some cases 250mb. To try to get around this, I have tried to reduce the graph size, for example 1000 x 1000. The result is shown below:

Image
As you can see, the proportions are all wrong in comparison to the previous chart

Is there a way to get a JPEG from the TChart? Or can I call some kind of method to get the quality I want, but not return a mammoth sized TBitmap? We are working with quite a lot of legacy code and I am sure there is good reason to make this images so large, but it is a real problem when we just want to extract a JPEG for printing.

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

Post by Narcís » Wed Dec 19, 2007 11:40 am

Hi Steve,

You could try using StretchDraw as shown here. You could then use a JPEG file as shown on this other thread.
As you can see, the proportions are all wrong in comparison to the previous chart
This is most likely because you are using absolute positions. You should set objects's custom position relative to some object in the chart, for example: series points, axes position, legend, title, etc.
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

Steve Chamberlain
Newbie
Newbie
Posts: 15
Joined: Mon Nov 20, 2006 12:00 am
Location: The Netherlands
Contact:

Post by Steve Chamberlain » Wed Dec 19, 2007 11:49 am

Thanks for the advice, I will see what I can do and report back.

Steve Chamberlain
Newbie
Newbie
Posts: 15
Joined: Mon Nov 20, 2006 12:00 am
Location: The Netherlands
Contact:

Post by Steve Chamberlain » Wed Dec 19, 2007 12:15 pm

Hi Narcis,

I am not sure how this code should look using the StretchDraw method. I would like to use a TJPEGImage object, so that it can be saved to a blob stream. I don't have a direct handle to the printing process as this is done via Crystal Reports, so using code like Printer.Canvas.StretchDraw is not possible.

I should mention also that the report can be generated even if the graph has not been created in the user interface. This means the graph is created in code, but there is sharing of code between UI and printing processes. This means using Chart->ClientRect gives an error (at least I think this error is related to the fact that it is not visible).

Many thanks for the help.

Steve Chamberlain
Newbie
Newbie
Posts: 15
Joined: Mon Nov 20, 2006 12:00 am
Location: The Netherlands
Contact:

Post by Steve Chamberlain » Wed Dec 19, 2007 1:14 pm

Hi Narcis,

I think I see what the problem is.

If I reduce the size of the graph, then the relative sizes of fonts, line widths etc are not resized. I think the best solution is to first reduce the size of the graphs overall and then also reduce the fonts, lines etc. I have tested this theory with the graph shown and it produces the sort of results I expect.

I do not understand why the graphs are as big as they are in the first place, but I am working with legacy code which was based on the standard TChart components from C++ Builder 6. Maybe there is a technical reason for it that is no longer applicable.

Thank you for all the help!

David
Newbie
Newbie
Posts: 4
Joined: Mon Oct 22, 2007 12:00 am

Post by David » Thu Feb 14, 2008 7:15 am

The other thing you can do is first render the chart to a metafile. Then do something like:

metafile.StretchDraw(bitmap.Canvas,rect(....))

I forget the exact syntax. But drawing to a metafile will preserve scaling properly so the stretchdraw will work well.

Steve Chamberlain
Newbie
Newbie
Posts: 15
Joined: Mon Nov 20, 2006 12:00 am
Location: The Netherlands
Contact:

Post by Steve Chamberlain » Thu Feb 14, 2008 7:19 am

I forgot how we solved this in the end, but it is now working.

We store the image as a JPEG, but for a number of users this generates an exception. In this case, the image is saved in bitmap format. We never found out what it is about the small group of users' systems that causes an exception to be generated.

Thanks for all the support!

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

Post by Narcís » Thu Feb 14, 2008 11:40 am

Hi Steve,

Thanks for the information. I'm glad to hear you found a solution.
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

Post Reply