Chart.ToImage() and Shapes.AddPicture() have issues

Hi,


If you run the following code on the given sample file by changing the image formats, you’ll observe the following:

Workbook w1 = new Workbook(“C:\Sample.xlsx”);
var chartPicStream = new MemoryStream();
w1.Worksheets[0].Charts[0].ToImage(chartPicStream, ImageFormat.Png);

w1.Worksheets[2].Shapes.AddPicture(18, 1, chartPicStream, 100, 100);

w1.Save(“C:\output .xlsx”);

1. With Bmp,Gif,Jpeg, formats, the image size is correct but the image itself is all wrong

2. With Emf, the image size is wrong and text in the shape beside the Value axis isn’t shown completely on the image

3. With Png, Tiff format, the image size is correct but the image has a lines around the chart area and texts in the text boxes beside both the value axes in bold. And again the complete text isn’t shown on the image.

Thanks

Hi Yashali,


Thank you for contacting Aspose support.

We have evaluated your presented scenarios while using the latest version of Aspose.Cells for .NET 8.4.1, and we are able to observe most of the mentioned issues except the following.

  • The text box containing the text “Hong Kong Dollar” does not have the correct width to fit all the text in it. If you increase the width of the text box and keep the contents of text box inside the chart area, the text will render correctly in the resultant image. Please check the modified.xlsx & output-modified-Emf.xlsx for your reference.
  • The scenario with EMF image type generates the image of same dimensions as of the chart it self. Please check the output-Emf.xlsx for your reference.

I am moving forward to log appropriate tickets for further investigation, and I will shortly get back to you with ticket details. In the meanwhile, could you please check the above two concerns for confirmation?

Hi again,


This is to inform you that we have logged two tickets in our database with the following details.

  • CELLSNET-43567: Converting Chart to image and inserting the image in worksheet renders the Chart Area in black.
  • CELLSNET-43568: Converting Chart to Image and inserting the image in worksheet renders the TextBox contents in bold.

Please note, we have used the modified spreadsheet (as shared in previous response) to evaluate the case related to the rendering of TextBox contents in bold. Moreover, we were not able to see any lines around to chart image when image format is specified as PNG or TIFF.

Please check the attached spreadsheets that were produced during our testing, and let us know if we have missed any thing.

Hi,

Thanks for your using Aspose.Cells.

We have fixed the issue.

  • CELLSNET-43597 - Image scales is wrong when insert emf image to sheet

Please download and try the latest fix: Aspose.Cells for .NET v8.4.1.2 and let us know your feedback.

Hi,

Thanks for using Aspose.Cells.

For the issues CELLSNET-43567 and CELLSNET-43568

Please try the fix: Aspose.Cells
for .NET v8.4.1.2
for size of Emf format not proper and text bold.

As the background color of chart is transparent, the Bmp and Jpeg must be black. You may test the issues using .net framework graphics api.

private static void TestDraw()

{

string dir = @"D:\tmp";

using (Bitmap b = new Bitmap(400, 400))

{

using (Graphics g = Graphics.FromImage(b))

{

System.Drawing.Font font = new System.Drawing.Font(“Calibri”, 12);

StringFormat sf = new StringFormat(StringFormat.GenericTypographic);

Rectangle rect = new Rectangle(100, 100, 200, 200);

string text = “This is (M) a <span style=“font-size:9.5pt;font-family:“MS Mincho”;color:#A31515” lang=“ZH-CN”>‱ test”;

g.DrawString(text, font, new SolidBrush(Color.Black), rect, sf);

g.DrawRectangle(new Pen(Color.Red), rect);

b.Save(dir + “test.jpeg”);

b.Save(dir + “test.png”);

}

}

}

The issues you have found earlier (filed as CELLSNET-43568) have been fixed in this update.


This message was posted using Notification2Forum from Downloads module by Aspose Notifier.

Hi,


Thanks for the fixes! Will let you know if I have any more queries.


Hi Yashali,


Please feel free to thoroughly test the new release and contact us back in case you face any difficulty.

Hi,


The image on sheet2 still has incorrect dimensions with version 8.4.2.0 (net3.5):

Workbook w1 = new Workbook(“C:\sample.xlsx”);

var chartPicStream = new MemoryStream();
w1.Worksheets[0].Charts[0].ToImage(chartPicStream, ImageFormat.Emf);

w1.Worksheets[2].Shapes.AddPicture(18, 1, chartPicStream, 100, 100);

w1.Save(“C:\output.xlsx”);

If you click on the image on sheet2 in output.xlsx, you will find that the actual image doesn’t cover the picture dimensions properly.

I have attached the sample file and an image describing how the actual image is only a part of the picture.

Hi Yashali,


I have reevaluated the presented scenario while using the latest version of Aspose.Cells for .NET 8.4.2. I am afraid, I am unable to replicate the said problem, that is; the image copied to 3rd worksheet is exactly of same size as of the original chart. Please check the attached snapshot for your reference. Please try a test on your end by selecting and copying the image from 3rd worksheet and pasting it over the chart in the 1st worksheet. You will notice that image & chart dimensions are same.

In case the problem persists on your side, please provide us an executable sample application along with its dependencies for further investigation.

It works for me with Aspose 8.5.1


Thanks

Hi Yashali,


Thank you for the confirmation. Please feel free to contact us back in case you need our further assistance with Aspose APIs.