Visual Studio 2022, dotnet core6
Steema.TeeChart.NET(4.2022.12.1)
After drawing the chart, I want to save it as an image.
I've drawn it with the function below, but the first one draws well, but from the second it draws everything in black.
If I open TeeChart Editor Tool and copy or save from the Export menu, a black image is saved.
Please check it.
TChart.Image.Bitmap.CopyToClipboard();
TChart.Export.Image.Bitmap.Save(fileNames);
dotnet core6 image export issue
-
- Guru
- Posts: 1603
- Joined: Fri Nov 15, 2002 12:00 am
Re: dotnet core6 image export issue
Hello,
the following code:
Successfully copies a bitmap to the clipboard and also produces a valid bitmap image in .NET 6.0 with NuGet v.4.2022.12.1. Could you please modify the above code so we can reproduce your problem here?
the following code:
Code: Select all
public Form1()
{
InitializeComponent();
InitializeChart();
}
private void InitializeChart()
{
var bar = new Bar(tChart1.Chart);
bar.FillSampleValues();
}
private void button1_Click(object sender, EventArgs e)
{
tChart1.Export.Image.Bitmap.CopyToClipboard();
tChart1.Export.Image.Bitmap.Save(@"C:\tmp\chart.bmp");
}
Best Regards,
Christopher Ireland / Development & Support Steema Software Avinguda Montilivi 33, 17003 Girona, Catalonia Tel: 34 972 218 797 http://www.steema.com |
Instructions - How to post in this forum |
Re: dotnet core6 image export issue
I found a sample when the problem occurs.
First, there is no problem when exporting an image with the button docked to the top and then the tchart docked to the fill.
However, if the tchart is first docked as fill and then the button is docked as top, a problem occurs when exporting the image. A black bar as high as the height of the button is displayed at the top.
please check this.
I hope for good news regarding this issue.
First, there is no problem when exporting an image with the button docked to the top and then the tchart docked to the fill.
Code: Select all
private TChart tChart1;
public Form1()
{
InitializeComponent();
Button btnOK = new Button();
btnOK.Text = "image";
btnOK.Dock = DockStyle.Top;
this.Controls.Add((Button)btnOK);
btnOK.Click += (s, e) =>
{
tChart1.Export.Image.Bitmap.CopyToClipboard();
};
tChart1 = new TChart();
tChart1.Dock = DockStyle.Fill;
this.Controls.Add(tChart1);
}
However, if the tchart is first docked as fill and then the button is docked as top, a problem occurs when exporting the image. A black bar as high as the height of the button is displayed at the top.
Code: Select all
private TChart tChart1;
public Form1()
{
InitializeComponent();
tChart1 = new TChart();
tChart1.Dock = DockStyle.Fill;
this.Controls.Add(tChart1);
Button btnOK = new Button();
btnOK.Text = "image";
btnOK.Dock = DockStyle.Top;
this.Controls.Add((Button)btnOK);
btnOK.Click += (s, e) =>
{
tChart1.Export.Image.Bitmap.CopyToClipboard();
};
}
please check this.
I hope for good news regarding this issue.
-
- Guru
- Posts: 1603
- Joined: Fri Nov 15, 2002 12:00 am
Re: dotnet core6 image export issue
Hello,
I obtain this:
Whereas with this code:
I obtain this:
This helps us to understand what is happening. When we add the Button to the Form's Controls collection _after_ we add the Chart, the Chart's Height area is reduced by the Height of the Button. When we add the Button to the Form's Controls collection _before_ we add the Chart, the Chart maintains the same Height as the Height of the Form's ClipRectangle. When the Chart's Height is reduced, we obtain the black rectangle, and when the Chart's Height isn't reduced we do not.
Our best suggestion is that you design your Windows Forms so that the addition of Controls to the Form's Controls collection does not reduce Height of the Chart. In the case of the code snippet that produces a black rectangle, the first snippet, removing the black rectangle involves moving a single line of code:
If I use this code:I hope for good news regarding this issue.
Code: Select all
private TChart tChart1;
public Form1()
{
InitializeComponent();
tChart1 = new TChart();
tChart1.Dock = DockStyle.Fill;
this.Controls.Add(tChart1);
Button btnOK = new Button();
btnOK.Text = "image";
btnOK.Dock = DockStyle.Top;
this.Controls.Add((Button)btnOK);
btnOK.Click += (s, e) =>
{
tChart1.Export.Image.Bitmap.CopyToClipboard();
};
this.Paint += (s, e) =>
{
MessageBox.Show($"ClipRectangle Height = {e.ClipRectangle.Height}, tChart1 Height = {tChart1.Height}, button Height = {btnOK.Height}");
};
}
Whereas with this code:
Code: Select all
private TChart tChart1;
public Form1()
{
InitializeComponent();
Button btnOK = new Button();
btnOK.Text = "image";
btnOK.Dock = DockStyle.Top;
this.Controls.Add((Button)btnOK);
btnOK.Click += (s, e) =>
{
tChart1.Export.Image.Bitmap.CopyToClipboard();
};
tChart1 = new TChart();
tChart1.Dock = DockStyle.Fill;
this.Controls.Add(tChart1);
btnOK.Click += (s, e) =>
{
tChart1.Export.Image.Bitmap.CopyToClipboard();
};
this.Paint += (s, e) =>
{
MessageBox.Show($"ClipRectangle Height = {e.ClipRectangle.Height}, tChart1 Height = {tChart1.Height}, button Height = {btnOK.Height}");
};
}
Our best suggestion is that you design your Windows Forms so that the addition of Controls to the Form's Controls collection does not reduce Height of the Chart. In the case of the code snippet that produces a black rectangle, the first snippet, removing the black rectangle involves moving a single line of code:
Code: Select all
diff --git a/ctl1.txt b/ctl2.txt
index 431ee06..13e3488 100644
--- a/ctl1.txt
+++ b/ctl2.txt
@@ -6,12 +6,12 @@
tChart1 = new TChart();
tChart1.Dock = DockStyle.Fill;
- this.Controls.Add(tChart1);
Button btnOK = new Button();
btnOK.Text = "image";
btnOK.Dock = DockStyle.Top;
this.Controls.Add((Button)btnOK);
+ this.Controls.Add(tChart1);
btnOK.Click += (s, e) =>
{
tChart1.Export.Image.Bitmap.CopyToClipboard();
Best Regards,
Christopher Ireland / Development & Support Steema Software Avinguda Montilivi 33, 17003 Girona, Catalonia Tel: 34 972 218 797 http://www.steema.com |
Instructions - How to post in this forum |
Re: dotnet core6 image export issue
That's not what I mean.
There is a problem with the image copied to the clipboard by clicking the btnOk button.
Similarly, the command below also has a black bar at the top.
tChart1.Export.Image.Bitmap.Save(@"C:\tmp\chart.bmp");
There is a problem with the image copied to the clipboard by clicking the btnOk button.
Similarly, the command below also has a black bar at the top.
tChart1.Export.Image.Bitmap.Save(@"C:\tmp\chart.bmp");
-
- Guru
- Posts: 1603
- Joined: Fri Nov 15, 2002 12:00 am
Re: dotnet core6 image export issue
Hello,
yes, that's what I referred to as the 'black rectangle' in my last message. You will find, as I said, that changing the position of that single line of code resolves the issue of a 'black rectangle' both when copying an image to the clipboard and saving an image to file.
Best Regards,
Christopher Ireland / Development & Support Steema Software Avinguda Montilivi 33, 17003 Girona, Catalonia Tel: 34 972 218 797 http://www.steema.com |
Instructions - How to post in this forum |
-
- Guru
- Posts: 1603
- Joined: Fri Nov 15, 2002 12:00 am
Re: dotnet core6 image export issue
Hello,
Just to be clear. This code:
gives me this image when I click the button:
Whereas this code:
gives me this image:
The difference between the code that gives me the bad image and the code that gives me the good image is a single line:
The reason for why this is happening I explain in my first reply. I trust that this makes the issue clear to you.
Just to be clear. This code:
Code: Select all
private TChart tChart1;
public Form1()
{
InitializeComponent();
tChart1 = new TChart();
tChart1.Dock = DockStyle.Fill;
this.Controls.Add(tChart1);
Button btnOK = new Button();
btnOK.Text = "image";
btnOK.Dock = DockStyle.Top;
this.Controls.Add((Button)btnOK);
btnOK.Click += (s, e) =>
{
tChart1.Export.Image.Bitmap.CopyToClipboard();
};
}
Code: Select all
private TChart tChart1;
public Form1()
{
InitializeComponent();
tChart1 = new TChart();
tChart1.Dock = DockStyle.Fill;
Button btnOK = new Button();
btnOK.Text = "image";
btnOK.Dock = DockStyle.Top;
this.Controls.Add((Button)btnOK);
this.Controls.Add(tChart1);
btnOK.Click += (s, e) =>
{
tChart1.Export.Image.Bitmap.CopyToClipboard();
};
}
Best Regards,
Christopher Ireland / Development & Support Steema Software Avinguda Montilivi 33, 17003 Girona, Catalonia Tel: 34 972 218 797 http://www.steema.com |
Instructions - How to post in this forum |