将图像放在电子表格 (Aspose Cells) 上时,如何防止图像大小发生变化?

How can I prevent my image from changing size when placing it on a spreadsheet (Aspose Cells)?

我有一个图像嵌入到我的解决方案中,用于 Winforms 应用程序的主要形式,也用于粘贴到传播sheet。图片大小为156X121.

我把它放在 sheet 上是这样的:

var ms = new MemoryStream();
_logo.Save(ms, ImageFormat.Png);
ms.Position = 0;
pivotTableSheet.Pictures.Add(0, _grandTotalsColumnPivotTable, ms);

然而,当它位于 sheet 上时,它会伸展并溢出到相邻的单元格中,部分遮挡其他数据:

如您所见,尺寸不再是156X121。高度增加了 25%。为什么?我该如何预防?

此代码:

MessageBox.Show(string.Format("image height is {0}", _logo.Height));
MessageBox.Show(string.Format("image width is {0}", _logo.Width));

...显示高度为“126”,宽度为“151”,与项目中的图像匹配。那么为什么改变了原来的尺寸呢?有没有 属性 我可以设置保持尺寸不变而不拉伸它?或者我怎样才能防止这种图像涂胶?

我觉得很奇怪,图片是一个尺寸(126X151),它的原始尺寸据称是 1.26" X 1.63",缩放后的尺寸是 1.57" X 1.63"。

是谁或什么允许高度增加 25%?

注意: 如果我 select 图像 "Size and Properties" 对话框中的 "Reset" 按钮,它会按我希望的那样缩小, 将高度 "back" 从 125% 设置为 100%。有没有办法以编程方式做到这一点 "Reset"?

更新

根据答案,我尝试了这个:

var ms = new MemoryStream();
//_logo.Height = 121; <= cannot set; Height is a readonly property
_logo.Save(ms, ImageFormat.Png);
ms.Position = 0;
pivotTableSheet.Pictures.Add(0, _grandTotalsColumnPivotTable, ms);

Picture pic = pivotTableSheet.Pictures[0];     
//Workbook.Worksheets[0].Pictures[0]; <= does not compile
pic.HeightScale = 100;
pic.WidthScale = 100;

(Workbook.Worksheets[0] 不适合我).

没有区别;图像仍在垂直拉伸。

更新 2

我意识到我需要 "Workbook" 才能成为 "workBook",因为:

private static Workbook workBook;

...所以我尝试了这个:

Picture pic = workBook.Worksheets[1].Pictures[0]; // Worksheet 0 is the data sheet that feeds the PivotTable and subsequently gets hidden, so need to use 1
pic.Height = 121;
pic.WidthScale = 100;

...但它仍然在垂直方向上模糊图像。将 "pic.Height = 121" 替换为 "pic.HeightScale = 100;"

也是如此

这是当前的代码,它添加了图像,但以垂直胶化的方式:

var ms = new MemoryStream();
//_logo.Height = 121; readonly
_logo.Save(ms, ImageFormat.Png);
ms.Position = 0;
pivotTableSheet.Pictures.Add(0, _grandTotalsColumnPivotTable, ms);
Picture pic = workBook.Worksheets[1].Pictures[0]; // Worksheet 0 is the data sheet that feeds the PivotTable
//pic.Height = 121;
pic.HeightScale = 100;
pic.WidthScale = 100;

请使用此代码将其重置为原始高度。

Picture pic = wb.Worksheets[0].Pictures[0];
pic.HeightScale = 100;
pic.WidthScale = 100;

注意:我在 Aspose 担任开发人员布道师