我使用以下代码将jpeg图像放到Visio绘图页面上,但每次运行我的应用程序时,我放下的图像将放在我丢弃的早期图像之上。我的问题是如何替换图像/形状,以便用新图像替换早期图像。 我尝试使用shpNew.ReplaceShape(imageFile,0);但它又重叠在早期的图像上。
我的另一个想法是删除早期形状并删除新图像。 请让我知道有效的方法。
private void DropImage(Visio.Page vPag, string imageFile)
{
if (vPag != null)
{
var shpNew = vPag.Import(imageFile);
//Set position
shpNew.CellsU["PinX"].FormulaU = "75mm";
shpNew.CellsU["PinY"].FormulaU = "175mm";
//Set size
shpNew.CellsU["Width"].FormulaU = "100mm";
shpNew.CellsU["Height"].FormulaU = "80mm";
}
}
答案 0 :(得分:0)
对于基于母版的形状,ReplaceShape方法仅
。Shape.ReplaceShape方法(Visio)
使用作为传递的主实例替换指定的形状 第一个参数,并返回新形状。
但 NOT 适用于所有visio形状和插入图像等异物 https://msdn.microsoft.com/en-us/library/office/jj229596.aspx?f=255&MSPPError=-2147217396
答案 1 :(得分:0)
我找到你以前的帖子:Insert an Jpeg/bmp image onto the visio drawing using VBA/C#
Sub v()
Dim shp As Shape
Dim os As Shape
Dim ns As Shape
Dim x As Single, y As Single
For Each shp In ActivePage.Shapes
' find images
If shp.Type = 4 Then
' define os variable as founded image
Set os = shp
End If
Next
If IsEmpty(os) Then
MsgBox "Picture not found"
Else
' define X and Y position
x = os.Cells("PinX")
y = os.Cells("Piny")
' insert new picture
Set ns = ActivePage.Import("c:\Users\Surrogate\Desktop\ycnex.png")
' place new shape to old shape coordinates
ns.Cells("pinx") = x
ns.Cells("piny") = y
' delete old shape
os.Delete
End If
End Sub