Tchart7 control image export Summary
-
1. Versions earlier than tchart7
-
2. tchart7 export BMP and WMF
-
3. tchart7 export JPG (JPEG)
-
4. tchart7 export GIF
-
5. tchart7 export PCX
-
6. tchart7 export htm
-
7. tchart7 export PNG
-
8. Conclusion
1. Versions earlier than tchart7
The tchart before tchart7 can be saved to the desired image format by using a method similar to chart1.export. savetoworkflow file. However, after tchart7, tchart does not have the export attribute. The following method is used to export the image. I try to use the code to illustrate the problem. If the details are not enough, I can query the corresponding source code for learning.
2. tchart7 export BMP and WMF
Tchart7 provides methods for exporting BMP and WMF, which can be called directly. The example is as follows:
Chart1.SaveToBitmapFile('c:/1.bmp');
Chart1.SaveToMetafile('c:/1.wmf');
3. tchart7 export JPG (JPEG)
Tchart7 exporting JPG (JPEG) is also relatively simple. In this unit, the uses teejpeg unit is executed, and then the teesavetojpeg or teesavetow.file in teejpeg is executed. Example:
// Be sure to include teejpeg.
Implementation
Uses
Teejpeg;
Procedure tform1.button2click (Sender: tobject );
Begin
Teesavetojpeg (chart1, 'c:/1.jpg ',-1,-1); // The following two parameters are width and height, if you use teechart, you can set the width and height to-1.
End;
4. tchart7 export GIF
Exporting GIF with tchart7 is more complicated. Use the code for example.
// Be sure to include teegif.
Implementation
Uses
Teegif;
Procedure tform1.button3click (Sender: tobject );
VaR
Exp: tgifexportformat;
FRM: tteegifoptions;
Begin
Exp: = tgifexportformat. Create;
Exp. Panel: = chart1;
FRM: = tteegifoptions (exp. Options ());
FRM. cb1_ction. itemindex: = 3;
Exp. savetofile ('C:/1.gif ');
Exp. Free;
End;
The above example is very representative for tchart7 image export. In fact, all formats can be exported in the above example, just replace tgifexportformat with the desired format, because all exports correspond to one format.
In the preceding example, an exported format class object is generated and the chart to be exported is set. If necessary, the export option is set. Please note that all export options in the format are set through the options () function of the format class, which is strange.
FRM must be set for GIF export. cbreduction. itemindex, because the default value of this item is 0, "color table error .... ", so it must be set to a non-zero value. What does each value mean? You can check it yourself.
5. tchart7 export PCX
The export of PCX from tchart7 is very similar to that from GIF. The sample code is as follows:
// Ensure that teepcx is included.
Implementation
Uses
Teepcx;
Procedure tform1.button4click (Sender: tobject );
VaR
Exp: tpcxexportformat;
Begin
Exp: = tpcxexportformat. Create;
Exp. Panel: = chart1;
Exp. savetofile ('C:/1. pcx ');
Exp. Free;
End;
6. tchart7 export htm
Ttchart7 can be exported directly to htm. in this unit, run the uses teevmlcanvas unit and then run the teesavetovmlfile in teevmlcanvas. Example:
// Be sure to include teevmlcanvas.
Implementation
Uses
Teevmlcanvas;
Procedure tform1.button5click (Sender: tobject );
Begin
Teesavetovmlfile (chart1, 'c:/1.html ');
End;
7. tchart7 export PNG
Ttchart7 can be easily exported to PNG. in this unit, run the uses teepng unit and then run the teesavetopng in teepng. Example:
// Be sure to include teepng.
Implementation
Uses
Teepng;
Procedure tform1.button7click (Sender: tobject );
Begin
Teesavetopng (chart1, 'c:/1.png ');
End;
Note that lpng. dll is required to save the PNG format. Therefore, you must download and install lpng. DLL to run the sample code normally.
8. Conclusion
This document describes how to use teechart7 to export images. code examples are provided for each method, and you want to summarize the exported images using tchart7.