Picture scale not correct

Hi all,
I’m using Aspose 19.2 and add a picture to worksheet.
But when I open it, picture scale is not correct (higher with DPI)
My DPI is 144, and when I don’t set column width, it work fine.
ConsoleApp1.zip (4.6 MB)

Thank you

@DungLT,
I have attached output files so could you please elaborate bit more with screenshots. We will provide our feedback after analysis.
Output.zip (39.2 KB)

Hi @ahsaniqbalsidiqui,
here is my screenshot, it same issue
Desktop.zip (402.2 KB)

@DungLT,
I am working on your query and will share my feedback soon.

1 Like

@DungLT,
We need to look into it more. We have logged the issue in our database for investigation and for a fix. Once, we will have some news for you, we will update you in this topic.

This issue has been logged as

CELLSNET-47033 - Picture scale not correct
1 Like

@DungLT,

We evaluated your issue further and found it is not an issue with Aspose.Cells. If an image is added in MS Excel, the physical width and height of the shape is adopted accordingly.

  1. Please set the DPI as 144 with the follwing codes:
CellsHelper.DPI = 144;
var _wb = new Workbook();
var _ws = _wb.Worksheets[0];
var _img = Image.FromFile(dir + @"Capture.PNG");
_ws.Cells.SetColumnWidthPixel(0, _img.Width);
using (var _ms = new MemoryStream(ImageToByteArray(_img)))
{
         var _pic = _ws.Pictures[_ws.Pictures.Add(0, 0, _ms, 100, 100)];
           _pic.Width = _img.Width;
          _pic.Height = _img.Height;
         _pic.WidthScale = 100;
        _pic.HeightScale = 100;            
}
  1. Please set the column’s width as :
    _ws.Cells.SetColumnWidthPixel(0,(int)( _img.Width * (96/144.0));

Hope, this helps a bit.

1 Like

Hi @Amjad_Sahi
I’m trying your code and it work fine.
Thanks for your support.

Best Regards

@DungLT,

Good to know that your issue is sorted out by the suggested code. Feel free to write us back if you have further comments or questions, we will be happy to assist you soon.

1 Like

@Amjad_Sahi
When I trying to add this code, it scale not correct:

var _defaulStyle = _wb.DefaultStyle;
_defaulStyle.Font.SchemeType = FontSchemeType.Minor;
_wb.DefaultStyle = _defaulStyle;

:frowning:

@DungLT,

Could you paste your complete sample code (runnable) with template file(s) to show the issue, we will check it soon. Also, attach a screenshot to highlight the issue.

@Amjad_Sahi
This is my attachment, include program, screenshot and file demo.

AsposeTestApp.zip (4.7 MB)

Thank & Best Regards

@DungLT,

Thanks for the sample project with sample files.

Please try our latest version/fix: Aspose.Cells for .NET v19.11.7:
Aspose.Cells19.11.7 For .Net2_AuthenticodeSigned.Zip (5.0 MB)
Aspose.Cells19.11.7 For .Net4.0.Zip (5.0 MB)
Aspose.Cells19.11.7 For .NetStandard20.Zip (4.1 MB)

I have tested using the following sample code with your image file and it works fine and as expected:
e.g
Sample code:

var _wb = new Workbook();

            var _defaulStyle = _wb.DefaultStyle;
            _defaulStyle.Font.SchemeType = FontSchemeType.Minor;
            _wb.DefaultStyle = _defaulStyle;

            var _ws = _wb.Worksheets[0];
            var _img = Image.FromFile("E:\\test2\\picturescalenot\\AsposeTestApp\\AsposeTestApp\\bin\\Debug\\Capture.PNG");


            _ws.Cells.SetRowHeightPixel(0, 409);
            _ws.Cells.SetColumnWidthPixel(0,(int)(_img.Width * (96/144.0)));

            using (var _ms = new MemoryStream(ImageToByteArray(_img)))
            {
                var _pic = _ws.Pictures[_ws.Pictures.Add(0, 0, _ms)];
                _pic.RelativeToOriginalPictureSize = true;
                _pic.WidthScale = 100;
                _pic.HeightScale = 100;
            }

            _wb.Save("e:\\test2\\out1.xls", SaveFormat.Excel97To2003);

Let us know if you still find picture scaling issue with v19.11.7.

@Amjad_Sahi
I’m tested but it still not true
Capture.PNG (41.2 KB)
2.PNG (96.3 KB)

@DungLT,

Thanks for the screenshots.

I noticed you are using 150% display settings which may cause your issue. Kindly try using 100% display settings for your os and then try the sample code (as I provided in previous post) with v19.11.7, it should work fine.

Let us know if you still find the issue.

I know If set to 100, it work fine. But my screen is hight resolution, when I set to 100%, text display is very small.

@DungLT,

I am afraid, there is no better way to cope with it.
By the way, could you try the line of code at the start of your code segment if it works fine:
e.g
Sample code:

......... 
 //Set dpi to 96
 CellsHelper.DPI = 96;
.......  

Hope, this helps a bit.