我在这方面有点新鲜,我遇到了从SQL Server表中将邮件合并到MS Word中的问题。这article。
我在Word中设置了一个书签作为图像的占位符(不确定这是否是最佳方式)。
问题是图像在Word中显示,但它太大了。
有没有办法在图像到达Word之前调整图像大小?
这是我的代码:
Dim r As DataRow
r = dtLicence(0)
Dim MyPhoto As Object
MyPhoto = r("Photo")
myImage = MyPhoto
Dim membits As New MemoryStream(myImage)
Dim WordPhoto As Image
WordPhoto = Image.FromStream(membits)
Clipboard.SetDataObject(WordPhoto)
word_server.Selection.GoTo( _
What:=Word.WdGoToItem.wdGoToBookmark, _
Name:="Photo")
With word_server.Selection
.Paste()
End With
如果有人可以为我提供一些代码示例,我会很感激。
答案 0 :(得分:0)
您可以尝试使用此功能调整图像大小:
WordPhoto = ScaleImage(Image.FromStream(membits), 300, 300)
这是我发现的功能:
Public Function ScaleImage(ByVal OldImage As Image, ByVal TargetHeight As Integer,_
ByVal TargetWidth As Integer) As System.Drawing.Image
Dim NewHeight As Integer = TargetHeight
Dim NewWidth As Integer = NewHeight / OldImage.Height * OldImage.Width
If NewWidth > TargetWidth Then
NewWidth = TargetWidth
NewHeight = NewWidth / OldImage.Width * OldImage.Height
End If
Return New Bitmap(OldImage, NewWidth, NewHeight)
End Function