在Html中,顯示svg,<object>看起來要比<embed>更加合適,因為當svg尺寸過大時,<object>只會對其縮放,而<embed>會將圖像裁剪掉 正所謂:既生瑜,何生亮。但是<object>是一個比<embed>更不正式的標簽!
如果你的svg需要給更多的人看,那麼使用<embed>是一個不錯的選擇!
很簡單,我們可以從svg讀出其width,height!
由於svg也是XML格式的,那麼就容易多了!
<%@ Import NameSpace="System.XML" %> 別忘了導入相應的名稱空間
方法如下:相應的函數的作用我就不詳細說明了,.Net Framework中都有詳細的說明
sub showSvgWindow(theSvgPath as string)
dim reader as XMLTextReader = Nothing
dim nodeAttri
BTion as new arrayList()
dim i,width,height as integer
reader = new XMLTextReader(server.MapPath(theSvgPath))
dim e
XP as exception
Try
While reader.Read()
If reader.NodeType = XMLNodeType.Element And reader.Name = "svg" Then
If reader.HasAttributes Then
For i = 0 to (reader.attributeCount-1)
reader.moveToAttribute(i)
If reader.Name = "width" Then
width = reader.Value
End If
If reader.Name = "height" Then
height = reader.Value
End If
Next
End If
Exit While
End If
End While
Catch exp
End Try
If CInt(width) < 50 Then
width = "50"
Else If CInt(height) < 50 Then
height = "50"
End If
svgWindow.Text = "<embed src=" & theSvgPath & " height=" & height & "px width=" & width & "px></embed>"
svgTitle.Text = request.QueryString("title")
end sub