Page 1 of 2
MetaFile loosing linestyle
Posted: Wed Oct 07, 2009 9:01 pm
by 10548769
Hi, i just want to know if you are planning on redoing the DrawToMetaFile function to avoid the Delphi bug where LineStyle are behing ignored in a metafile. If my graph got some psDot, i will lose that style once exported to a metafile. (Append only when you resize the metafile about 1.5x the original size). I did some test and if i simulate the style of a pen (MoveTo,LineTo for a Dot line), it work #1 in a metafile. Hope i was clear enought for you to understand me hehehehhe
Thanks again
Re: MetaFile loosing linestyle
Posted: Thu Oct 08, 2009 10:56 am
by yeray
Hi GoToXY,
I've found that the line series style isn't drawn correctly when having the pen wider and saving the chart to windows metafile (wmf). But the exportation works fine exporting to enhanced metafile (emf). Is that what you are reproducing? Here is the code I used:
Code: Select all
procedure TForm1.FormCreate(Sender: TObject);
begin
Chart1.View3D := false;
Chart1.Legend.Visible := false;
Chart1.AddSeries(TLineSeries.Create(self));
Chart1[0].FillSampleValues(25);
Chart1[0].Pen.Style := psDash;
Chart1.SaveToMetafile('C:\tmp\test1.wmf'); //correct
Chart1.SaveToMetafileEnh('C:\tmp\test1.emf'); //correct
Chart1[0].Pen.Width := 2;
Chart1.SaveToMetafile('C:\tmp\test2.wmf'); //incorrect
Chart1.SaveToMetafileEnh('C:\tmp\test2.emf'); //correct
end;
Re: MetaFile loosing linestyle
Posted: Thu Oct 08, 2009 12:33 pm
by 10548769
I need it in memory, so i use a TMetaFile and a TMetaFileCanvas, i do Chart.drawToMetaFile then TheMetaFile.SaveToStream. I always had that problem with delphi (with my other software) so i touhg you could have already done some function to simulate the drawing to make emf keep track of linestile with 1 width.
Re: MetaFile loosing linestyle
Posted: Thu Oct 08, 2009 1:12 pm
by 10548769
I checked it doing SaveToFile and thats true: EMF = Good, WMF = 2x bigger and not good. So if i would savethem to disk it would have been perfect but since i need to use it in memory the only way i know is SaveToStream but that function doesnt allow me to save it in EMF Format.
Any Idea ?
Re: MetaFile loosing linestyle
Posted: Thu Oct 08, 2009 1:35 pm
by 10548769
oh well, i did other test and it seems Delphi cant print EMF correctly anyway
And TImage dont display it correctly too. Looks like im screw lol
Re: MetaFile loosing linestyle
Posted: Tue Oct 13, 2009 9:29 am
by yeray
Hi GoToXY,
Excuse us for the delay. Please take a look at this example of how you could create a metafile from a chart. Note that I draw it to a TImage component to see if the pen is stored fine:
Code: Select all
uses series;
procedure TForm1.FormCreate(Sender: TObject);
var tmpMeta: TMetafile;
begin
Chart1.View3D := false;
Chart1.Legend.Visible := false;
Chart1.AddSeries(TLineSeries.Create(self));
Chart1[0].FillSampleValues(25);
Chart1[0].Pen.Style := psDash;
Chart1[0].Pen.Width := 2;
tmpMeta := Chart1.TeeCreateMetafile(False,Chart1.ClientRect);
try
Image1.Canvas.StretchDraw(Rect(0,0,Image1.Width, Image1.Height),tmpMeta);
finally
tmpMeta.Free;
end;
end;
Re: MetaFile loosing linestyle
Posted: Tue Oct 13, 2009 12:32 pm
by 10548769
Hi Yeray,
For the series, everything is fine, but not for the grid. The Axis (Left and Bottom) grids became lines on printing resizing.
BTW: Thx for letting me know about that function, that will save me lots of lines in my softwares
tmpMeta := Chart1.TeeCreateMetafile(False,Chart1.ClientRect);
After changing False to True (because i needed Enhance MF) saving is good and every line that have a style are displayed with that style with Windows picture viewer. But when it comes to view it in Delphi, Grids line are still in solid style. I did other test and it seem to happend only when the width of the line = 1. So i presume that you used a custom DrawLine when width are greater than 1, but should be anytime to solve Delphi bug being unabled to display MEtaFile correctly. I wish im correct and it can be solve.
Re: MetaFile loosing linestyle
Posted: Wed Oct 14, 2009 10:42 am
by yeray
Hi GoToXY,
Could you please send us a simple example project or a complete (but simple) code snipped we can run as-is here to reproduce it?
Thanks in advance.
Re: MetaFile loosing linestyle
Posted: Wed Oct 14, 2009 12:19 pm
by 10548769
Hi, ive attached a Simple Application that reproduce the bug with 3 ScreenShot taken from my computer. Hope we can do something about it
Thanks a lot and have a good day.
Re: MetaFile loosing linestyle
Posted: Wed Oct 14, 2009 1:33 pm
by yeray
Hi GoToXY,
Ah, excuse me, the mistake was on my suggestion. This line is creating a metafile in the same size of the chart and can present problems if you want to resize it:
Code: Select all
tmpMeta := Chart1.TeeCreateMetafile(False,Chart1.ClientRect);
So I recommend you to create that metafile in the final size so that the chart will be redrawn internally to that size and the image will look better:
Code: Select all
tmpMeta := Chart1.TeeCreateMetafile(True,Rect(0,0,Image1.Width,Image1.Height));
Re: MetaFile loosing linestyle
Posted: Wed Oct 14, 2009 1:55 pm
by 10548769
Hi Yeray,
I dont really understand what you are suggesting me. I am using MetaFile because metafile are Vectors It should look very nearly the same on any size. Why i am using MetaFile is for an easy way to Show / Print and store the Chart so i can use it in several other application. I didnt went through all your line of code, but im pretty sure this bug happend because the width of the line is equal to 1 and im pretty sure, you dont use a custom draw to simulation a linestyle when its equal to 1 because delphi should manage it already by himself. But in fact, Delphi dont really managed it by himself because when you resize a metafile with linestyle and width = 1 using regular API ported in delphi, you will lose all linestyle when you resize it bigger than the original. I havent tried it on a C# or C++ application, but im pretty sure it should work fine.
Re: MetaFile loosing linestyle
Posted: Thu Oct 15, 2009 2:22 pm
by yeray
Hi GoToXY,
GoToXY wrote:Why i am using MetaFile is for an easy way to Show / Print and store the Chart so i can use it in several other application
Maybe you should consider using tee files to port your charts from an application to another.
GoToXY wrote:But in fact, Delphi dont really managed it by himself because when you resize a metafile with linestyle and width = 1 using regular API ported in delphi, you will lose all linestyle when you resize it bigger than the original
Yes, I guess there could be a problem in delphi's canvas and we can't do too much here. But, if you could send us an example showing that we'll be glad to take a look at it.
Re: MetaFile loosing linestyle
Posted: Thu Oct 15, 2009 2:24 pm
by 10548769
i already sent a simple application attached to one of my message. If you need it by mail, can you tell me which email to send it to.
Thanks
Re: MetaFile loosing linestyle
Posted: Thu Oct 15, 2009 2:30 pm
by yeray
Hi GoToXY,
I understood that you could reproduce the problem without using teechart: "using regular API ported in delphi". And the application you sent on 14th Oct you are using TeeChart, isn't it?
Re: MetaFile loosing linestyle
Posted: Thu Oct 15, 2009 2:38 pm
by 10548769
Yes, i am using it. But i wonder why you ask that question because there is no LineTo in the source ive sent you. Did you check the simple application i sent you ? Dont take it the wrong way, but you should have known that answer just by looking at my source code.