Page 1 of 1

TeeCreateBitmap Memory Problem - TChart

Posted: Wed Dec 19, 2007 11:16 am
by 9243129
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.

Posted: Wed Dec 19, 2007 11:40 am
by narcis
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.

Posted: Wed Dec 19, 2007 11:49 am
by 9243129
Thanks for the advice, I will see what I can do and report back.

Posted: Wed Dec 19, 2007 12:15 pm
by 9243129
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.

Posted: Wed Dec 19, 2007 1:14 pm
by 9243129
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!

Posted: Thu Feb 14, 2008 7:15 am
by 10547089
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.

Posted: Thu Feb 14, 2008 7:19 am
by 9243129
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!

Posted: Thu Feb 14, 2008 11:40 am
by narcis
Hi Steve,

Thanks for the information. I'm glad to hear you found a solution.