如何防止图像在放置在电子表格(Aspose Cells)上时发生尺寸变化?

我有一个embedded到我的解决scheme中的图像,用于Winforms应用程序的主窗体,也用于粘贴到电子表格中。 图像大小是156X121。

我把它放在表单上,​​就像这样:

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

然而,当它在表格上时,它伸出并溢出到相邻的单元格中,部分掩盖了其他数据:

在这里输入图像说明

正如你所看到的,尺寸不再是156X121。 身高已经增加了25%。 为什么? 我怎样才能防止呢?

此代码:

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

…显示我的高度为“126”,宽度为“151”,与项目中的图像相匹配。 那么为什么原来的尺寸改变了? 我可以设置一个属性来保持大小,而不是拉伸吗? 或者我怎样才能防止这个形象的gumbification?

对我来说,这个图像是一个尺寸(126X151),原来的尺寸是1.26“×1.63”,缩放后的尺寸是1.57“×1.63”。

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

注意:如果我在图像的“大小和属性”对话框中select了“重置”button,它会缩小到我想要的位置,将高度从“125%”设置为100%。 有没有办法做到这一点“重置”编程?

UPDATE

基于这个答案,我尝试了这个:

 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

我意识到我需要“工作簿”是“工作簿”,因为这个:

 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; 

…但它仍然垂直地咕the着图像。 那么用“pic.HeightScale = 100”代替“pic.Height = 121”

所以这是目前的代码,它增加了图像,但是以垂直方式:

 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作为Developer Evangelist工作