An unsuccessful attempt to display SVG using the WebBrowser control

Source: Internet
Author: User

An unsuccessful attempt to display SVG using the WebBrowser control

The project needs to display and manipulate SVG in a window application, and I think of three ways:
1, the development and implementation of the SVG display and operation
This approach requires more work, involves understanding the SVG standards, selecting the implementation part (after all, the standard is too large), and using graphics implementations such as Directx,opengl or Java awt/swing, WINDOWS GDI, and so on to render SVG.
If the goal of the project is to provide a reusable SVG renderer, or it can be used if the SVG scope is small and the functionality is more specific. This approach is therefore not considered.

2, using the third-party SVG implementation
Using batik makes it easier to create Java applications that support SVG. There are also some SVG implementations based on C # in the SVG wiki, such as the sharp Vector Graphics,
However, in April 2003 after the release of 0.3 has not been updated, can only refer to use.

3, embed the browser page in the application
The third approach is to use the browser or browser plug-in's SVG capabilities to embed the browsers in the window application. This method looks the simplest, but the real problem is the most.

The first is to ensure that the browser on the installed machine can also display SVG (ie need to install other plug-ins such as ASV) after the release. Second debugging is more difficult, involving applications, browser controls, SVG plug-ins and so on.
Finally, if you want to manipulate SVG from an application, or the state of SVG to a control in a window, you need to implement the communication between the application window and the script, which was a bit cumbersome in the past.

In the WebBrowser control provided in. NET FRAMEWORK2.0, it provides the ability to interoperate between scripts and Windows.

such as calling a script in a window
WebBrowser1.Document.InvokeScript ("Test", new string[] {"Called from Client Code"});
Where the test function is the JS function in the page, receive a string parameter
function test (message) {alert (message);}

It is also convenient to call a window function in a script:
<button onclick= "Window.external.Test (' called From Script code ')" >call Windows code from script</button>
which
Test is a function in the window in which WebBrowser1 is located

This seems to indicate that using the WebBrowser control can easily display and manipulate SVG in a. NET FRAMEWORK2.0 window application, but there are still many problems in actual use.

WebBrowser controls can be loaded in a variety of ways for HTML, including navigate methods
WebBrowser1.Navigate ("test.html");

or directly set DocumentText
 webbrowser1.documenttext =
            "             "function test (message) {alert (message);}" +
            "</script>             "onclick=/" window.external.Test (' called From Script code ')/">" +
            "Call client code from script code</button>" +
            "</body>

or enter from a stream
StreamReader sr = new StreamReader ("test.html");
Webbrowser1.documentstream = Sr. BaseStream;

For these three ways, the WebBrowser control can display the contents of the HTML document correctly. When SVG is changed, the SVG content cannot be displayed even if the ASV IE is installed.

I had to embed SVG in HTML,
<embed id= "Bindsvg" src= "Test.svg" width= "-" height= "type=" Image/svg+xml "></embed>
And then as HTML display.

The situation has improved slightly, and the SVG contour is displayed because the HTML indicates that an SVG object was embedded, but IE did not find the SVG file, although it was placed in the same directory as the HTML.
This may be related to the browser's domain security features. However, as a local implementation of the application should not have this problem.

After you change the address to the URL address,
<embed id= "Bindsvg" src= "Http://localhost/testproject/test.svg" width= "" height= "type=" Image/svg+xml " ></embed>
SVG was finally shown. However, as a window application, you want to be able to display local SVG content instead of Web pages. The problem has not actually been solved.

Even with this approach, there are many problems in the operation, especially when using an SVG page, the application becomes unstable, less than 10 operations are unresponsive, and it is not known to be a problem with the WebBrowser control.
Or the problem of ASV Plug-ins, debugging has become very difficult.

After this unsuccessful attempt, I finally gave up the effort to use this approach.  

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.