How can I use tags to display a complete svg image?

Source: Internet
Author: User
 
To display svg in html, <object> looks more suitable than <embed> because when the svg size is too large, <object> only scales it, and <embed> will crop the image
It is said that he Shengliang, both Shengyu. But <object> is a tag that is less formal than <embed>!
If your svg needs to be shown to more people, using <embed> is a good choice!
It's easy. We can read its width and height from svg!
Because svg is also in XML format, it is much easier!
<% @ Import NameSpace = "System. XML" %> do not forget to Import the corresponding NameSpace.
The method is as follows: I will not elaborate on the functions of the corresponding functions, and the. NET Framework has detailed descriptions.
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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.