excel中有张图,复制到剪贴版,以bitmap格式保存后,图片就变小了,为什么?
代码如下:
Dim bitmap1 As Bitmap = GetShapeImage(shp)
bitmap1.Save(fp)
函数GetShapeImage代码:
Public Shared Function GetShapeImage(ByVal shp As Excel.Shape) As Bitmap
On Error Resume Next '获取Excel中的Shape并转为image
Clipboard.Clear() '清空
shp.CopyPicture(Appearance:=Excel.XlPictureAppearance.xlScreen, Format:=Excel.XlCopyPictureFormat.xlBitmap)
If Clipboard.GetDataObject.GetDataPresent(DataFormats.Bitmap) Then 'Clipboard.ContainsImage() Then
Dim curImage As System.Drawing.Image = Clipboard.GetImage()
Return curImage
End If
Return Nothing
End Function
保存后再导入图片,就发现图片变小了,应该是保存时就已经变小了。
现在改成这种方式,图片大小就正常了:
shp.CopyPicture()
With ActiveSheet.ChartObjects.Add(0, 0, shp.Width, shp.Height).Chart
.Parent.Select()
.Paste()
'.chartBorder.linestyle = Excel.XlLineStyle.xlLineStyleNone
.ChartArea.Border.linestyle = Excel.XlLineStyle.xlLineStyleNone
'.ChartArea.Format.Line.Visible = False
.Export(fp)
.Parent.Delete()
End With
求解?想知道原因。