Page 1 of 1

Blurred bitmaps frim TChart

Posted: Thu Nov 06, 2014 2:50 pm
by 16569982
Hi,
I just upgraded from Delphi 2010 and an older TeeChart version to Delphi XE6 and the current TeeChart from September 2014. I noticed that in the new version the bitmap output from TChart is blurred. This affects both the direct visual output to the screen, and the output of TChart.TeeCreateBitmap. In the chart editor and object inspector I could not find any new setting that would allow to switch between sharp and soft output, so I assume that it may be a bug.

I have added details from 6 screen shots, which for convenience I have assembed in one image. The top row shows the old version, and the bottom row the new version. Please zoom into the image so you can better see the problem.
On the left you see the direct output of the TChart on the screen. Note how all output (axis lines, axis labels and glyphs) is blurred now, compared to the sharp mouise pointer.
In the middle you can see the glyphs created from TChart.TeeCreateBitmap and then assigned to TSpeedButton.Glyph. They are blurred in the same way, while they were sharp in the past.
On the right side you can see the glyphs created from TChart.TeeCreateMetafile and then assigned to TImage.Picture.Metafile. They remain sharp also in the new version, which means that the general drawing in the TChart appears to be ok, and the problem only arises from the last step of rendering.

The glyphs now look different from the old version, e.g. the black outline of the red square has open cerners now, while thes were closed in the past. Have you changed the shapes of the glyphs with purpose?

Any suggestions? Thanks in advance for your help. Regards Uwe

[img]
BlurredBitmap.tif
BlurredBitmap.tif (506.4 KiB) Viewed 12161 times
[/img]

Re: Blurred bitmaps frim TChart

Posted: Fri Nov 07, 2014 9:10 am
by narcis
Hi UweK,

This is because GDI+ is now the default rendering canvas for aesthetic purposes. You can overcome that disabling the GDI+ canvas before exporting though:

Code: Select all

procedure TForm1.Button1Click(Sender: TObject);
var
  bmp: TBitmap;
  mtf: TMetafile;
  tmp: String;
begin
  Chart1.Canvas:=TTeeCanvas3D.Create;

  tmp:=Chart1.Title.Text[0];
  Chart1.Title.Text[0]:='Bitmap';
  bmp:=Chart1.TeeCreateBitmap(clNone, Chart1.ChartBounds);
  Image1.Picture.Bitmap:=bmp;
  bmp.SaveToFile('blurred.bmp');

  Chart1.Title.Text[0]:='Metafile';
  mtf:=Chart1.TeeCreateMetafile(True, Chart1.ChartBounds);
  Image2.Picture.Metafile:=mtf;
  mtf.SaveToFile('non-blurred.emf');

  Chart1.Title.Text[0]:=tmp;

  Chart1.Canvas:=TGDIPlusCanvas.Create;
end;
Which produces this:
BitmapvsMetafile.jpg
BitmapvsMetafile.jpg (86.6 KiB) Viewed 12039 times
Find also attached the complete project.

Re: Blurred bitmaps from TChart

Posted: Wed Nov 12, 2014 11:20 am
by 16569982
Hi,
Thanks for your suggestion. Unfortunately it brings only a partial solution to return to the old canvas with
"Chart1.Canvas:=TTeeCanvas3D.Create;"

(1) It works fine with a TChart that contains e.g. TPointSeries or TLineSeries. Both the direct display on the screen and the output of TeeCreateBitmap are sharp again now as they were with my old version (glyphs, lines, axis ticks, label text etc.)

(2) But there is a problem when I do the same with a TChart that contains a TColorGridSeries. The axis ticks and label texts become sharp like in (1) - that's ok. The little colored squares for the data points remain sharp - strangely, these have never been blurred even with the GDI+ canvas. But with the old TTeeCanvas3D set, the display of the TChart on the screen freezes. It won't change anymore even if I zoom into it on the screen with the mouse, or change the Color palette, or even change the data values in the TColorGridSeries. But the TChart is internally working well. I can see that if I create a metafile of it with TeeCreateMetafile. Only the bitmap output to the screen is dead.

Do you have any idea what happens?
Thanks. Regards, Uwe

Re: Blurred bitmaps from TChart

Posted: Wed Nov 12, 2014 3:04 pm
by yeray
Hello UweK,
UweK wrote:(2) But there is a problem when I do the same with a TChart that contains a TColorGridSeries. The axis ticks and label texts become sharp like in (1) - that's ok. The little colored squares for the data points remain sharp - strangely, these have never been blurred even with the GDI+ canvas. But with the old TTeeCanvas3D set, the display of the TChart on the screen freezes. It won't change anymore even if I zoom into it on the screen with the mouse, or change the Color palette, or even change the data values in the TColorGridSeries. But the TChart is internally working well. I can see that if I create a metafile of it with TeeCreateMetafile. Only the bitmap output to the screen is dead.
Check Chart1.AutoRepaint is true.
If this is not the problem, please try to arrange a simple example project we can run as-is to reproduce the problem here.

Re: Blurred bitmaps frim TChart

Posted: Thu Nov 13, 2014 2:54 pm
by 16569982
Hi,
It is not the AutoRepaint. That would have probably been too easy to guess.

I have silightly modified the test project from your previous post. I deleted your TChart from the form, and inserted the TChart from my application form with copy & paste, so it should have the same settings as in my project. To the TColorGridSeries I assign some dummy values in TForm.OnCreate. To have it similar to my program, I also moved the "Chart1.Canvas:=TTeeCanvas3D.Create" to TForm.OnCreate, because I only do it once for the TChart that is permanently displayed in the form.

First compile and run the program as it is, with the "Chart1.Canvas:=TTeeCanvas3D.Create" commented out so that the new TGDIPlusCanvas remains in effect. E.g. zoom into the TChart with the mouse, and everything is fine (except for the blurred bitmap).

Now remove the comment characters around "Chart1.Canvas:=TTeeCanvas3D.Create" and recompile the program. The program starts with a message "Wrong parameter", on my PC it is in German. Then the behaviour of this test project is different from my program, but this may be because I have lots of other actions in between. Here you will never see the plot of the TColorGridSeries, while in my program at least I get it once, before the screen output of the TChart freezes. But the entire problem may completely disappear anyway when you find the reason for that error message.

If the line "Chart1.Canvas:=TTeeCanvas3D.Create" is moved into the TBitBtn.OnClick like in your project, the TChart is displayed in the beginning, and the bug occurs later when e,g, I try to zoom into the TChart with the mouse.

Regards, Uwe

Re: Blurred bitmaps frim TChart

Posted: Fri Nov 14, 2014 12:00 pm
by yeray
Hello,

I'm getting an "Out of system resources" error as soon as I activate GDI (TTeeCanvas3D). But I can run it with a slight modification:

Code: Select all

procedure TForm1.FormCreate(Sender: TObject);
var I, J: Integer;
begin
  Caption:=TeeMsg_Version;  // to verify what TeeChart version is being used

  //Chart1.Canvas:=TTeeCanvas3D.Create; // activate this line to see the bug
  with ScreenSeries do
  begin
    Clear;
    for I:= 0 to 20 do
      for J:= 0 to 20 do
        AddXYZ(I, I+J, J);
    UsePalette:= true;
  end; {with ScreenSeries}
end;
UweK wrote:First compile and run the program as it is, with the "Chart1.Canvas:=TTeeCanvas3D.Create" commented out so that the new TGDIPlusCanvas remains in effect. E.g. zoom into the TChart with the mouse, and everything is fine (except for the blurred bitmap).
With the modification above, this is what I get in GDIPlus (TTeeCanvas3D.Create line commented out):
ColorGrid_GDIPlus.png
ColorGrid_GDIPlus.png (32.72 KiB) Viewed 11962 times
ColorGrid_GDIPlus_Zoomed.png
ColorGrid_GDIPlus_Zoomed.png (22.89 KiB) Viewed 11942 times
UweK wrote:Now remove the comment characters around "Chart1.Canvas:=TTeeCanvas3D.Create" and recompile the program. The program starts with a message "Wrong parameter", on my PC it is in German. Then the behaviour of this test project is different from my program, but this may be because I have lots of other actions in between. Here you will never see the plot of the TColorGridSeries, while in my program at least I get it once, before the screen output of the TChart freezes. But the entire problem may completely disappear anyway when you find the reason for that error message.
I don't see any of these problems here.
Using GDI (TTeeCanvas3D.Create line uncommented), this is what I get:
ColorGrid_GDI.png
ColorGrid_GDI.png (27.67 KiB) Viewed 11941 times
ColorGrid_GDI_Zoomed.png
ColorGrid_GDI_Zoomed.png (20.04 KiB) Viewed 11932 times
So I'm afraid I'm not sure to see anything blurred.
UweK wrote:If the line "Chart1.Canvas:=TTeeCanvas3D.Create" is moved into the TBitBtn.OnClick like in your project, the TChart is displayed in the beginning, and the bug occurs later when e,g, I try to zoom into the TChart with the mouse.
I only see a TGDIPlusCanvas commented out at the end of your Button1Click method. As it is, this is being applied to the main chart immediately but only to the bitmaps the next time the button will be called. This may be the explanation of the behaviour you are observing.
If I change it for what NarcĂ­s suggested, the main chart will be using GDIPlus and the exported charts should be in GDI:

Code: Select all

  Chart1.Canvas:=TTeeCanvas3D.Create;

  tmp:=Chart1.Title.Text[0];
  Chart1.Title.Text[0]:='Bitmap';
  bmp:=Chart1.TeeCreateBitmap(clNone, Chart1.ChartBounds);
  Image1.Picture.Bitmap:=bmp;
  bmp.SaveToFile('blurred.bmp');

  Chart1.Title.Text[0]:='Metafile';
  mtf:=Chart1.TeeCreateMetafile(True, Chart1.ChartBounds);
  Image2.Picture.Metafile:=mtf;
  mtf.SaveToFile('non-blurred.emf');

  Chart1.Title.Text[0]:=tmp;

  Chart1.Canvas:=TGDIPlusCanvas.Create;
ColorGrid_GDIPlus_to_GDI.png
ColorGrid_GDIPlus_to_GDI.png (32.33 KiB) Viewed 11933 times

Re: Blurred bitmaps frim TChart

Posted: Mon Nov 17, 2014 1:43 pm
by 16569982
Hi,
Maybe this is a misunderstanding, so let me explain again.

We already found out that the blurred image *only* is caused by the usage of the new GDI+ canvas that is now the default canvas when I use a TChart. So the solution is just to use the old Tee canvas: "Chart1.Canvas:= TTeeCanvas3D.Create;", and all bitmaps are sharp again, both on the direct screen display, and in the result of TeeCreateBitmap. That problem has been solved.

But when I switch to the old TTeeCanvas3D, I experience a completely new problem. The solution described above only works when the TChart contains TPointSeries or TLineSeries (and possibly others that I never use). But when the TChart contains TColorGridSeries, then I get a runtime error "Out of system ressources" (as Yeray has confirmed in the last posting) using the following source code:

Code: Select all

procedure TForm1.FormCreate(Sender: TObject);
var I: Integer;
begin
  Chart1.Canvas:= TTeeCanvas3D.Create;
  with ScreenSeries do
  begin
    Clear;
    for I:= 0 to 20 do   //this line different from below
      AddXYZ(I, I, I);    //this line different from below
    UsePalette:= true;
  end; {with ScreenSeries}
end;
The error never appeared with TTeeCanvas3D in previous TeeChart versions, and it also never appears when I use the detault TGDIPlus canvas in the current version.

So Yeray simply assigned different data values to the TColorGridSeries:

Code: Select all

procedure TForm1.FormCreate(Sender: TObject);
var I, J: Integer;
begin
  Chart1.Canvas:= TTeeCanvas3D.Create;
  with ScreenSeries do
  begin
    Clear;
    for I:= 0 to 20 do           //this line different from above
      for J:= 0 to 20 do        //this line different from above
        AddXYZ(I, I+J, J);     //this line different from above
    UsePalette:= true;
  end; {with ScreenSeries}
end;
and suddenly the "Out of system ressources" error has disappeared. So my new question is: What happens here? Is there a bug in the TColorGridSeries so that with certain data values assigned it does not work anymore in the TTeeCanvas3D, while with just other data valkues assigned it does work?

Thanks, Uwe

Re: Blurred bitmaps frim TChart

Posted: Tue Nov 18, 2014 12:17 pm
by yeray
Hello Uwe,

I see that code worked in TeeChart VCL v2014.10 and started to give this "Out of system resources" error in v2014.11.
However, note 3D series types aren't expected to be populated as you did. Please, read the explanation here about how to populate this type of series.

Re: Blurred bitmaps frim TChart

Posted: Tue Nov 18, 2014 1:11 pm
by 16569982
Thank you very much. The problem has been solved, by completely populating the data in the TColorGridSeries. I was not aware that obviously for years I have used the TColorGridSeries in an improper way, and it possibly only accidentally worked with my particular structure of data in previous TeeChart versions.

Here is just some additional information, to which you do NOT need to reply to me, but which may be useful when you debug this problem for a future version:
Setting "IrregularGrid:= true" also does not properly work with the old TTeeCanvas3D when the TColorGridSeries is not fully populated. Try this:

Code: Select all

procedure TForm1.FormCreate(Sender: TObject);
var I, J: Integer;
begin
  Chart1.Canvas:= TTeeCanvas3D.Create;
  with ScreenSeries do
  begin
    Clear;
    for I:= 0 to 20 do
      AddXYZ(I, I, I);
    IrregularGrid:= true;
    UsePalette:= true;
  end; {with ScreenSeries}
end;
=> On my PC now I don't get the "Out of system ressources" runtime error anymore, but the data points are very incorrectly displayed on the screen.

Also the drawing of an additional metafile over the TChart client area in the TChart.OnAfterDraw event does not properly work anymore with the old TTeeCanvas3D, while it was fine with TTeeCancas3D in older TeeChart versions. But it is still fine with the new GDI+ canvas, so I just use that:

Code: Select all

procedure Chart1.Chart1OnAfterDraw(ASender: TObject);
begin
    with Chart1 do
      Canvas.Draw(Width - AnyAdditionalMetafile.Width + 1, ChartRect.Top, AnyAdditionalMetafile);
end;
=>On my PC with the TTeeCanvaas3D the Text contained in the additional metafile is displayed on the screen with a very rough pixel pattern, like a magnified bitmap, and not as smooth as the rendering of a vector-type TMetafile graphics content to the screen should be.