以文本方式查看主题

-  中文XML论坛 - 专业的XML技术讨论区  (http://bbs.xml.org.cn/index.asp)
--  『 SVG/GML/VRML/X3D/XAML 』  (http://bbs.xml.org.cn/list.asp?boardid=21)
----  如何使用标签显示完整的svg图像?[推荐]  (http://bbs.xml.org.cn/dispbbs.asp?boardid=21&rootid=&id=26219)


--  作者:求索
--  发布时间:1/7/2006 2:38:00 PM

--  如何使用标签显示完整的svg图像?[推荐]
如何使用标签显示完整的svg图像?
在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 nodeAttribtion as new arrayList()
dim i,width,height as integer

reader = new xmlTextReader(server.MapPath(theSvgPath))
dim exp 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


--  作者:求索
--  发布时间:1/12/2006 10:12:00 AM

--  
没人顶,我自己顶!
--  作者:foxgst
--  发布时间:1/17/2006 3:25:00 AM

--  
xhtml 1.1中不是不支持embed标签了吗?
W 3 C h i n a ( since 2003 ) 旗 下 站 点
苏ICP备05006046号《全国人大常委会关于维护互联网安全的决定》《计算机信息网络国际联网安全保护管理办法》
6,562.500ms