亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

從Windows環境調用javascript函數來生成myfile.svg?

從Windows環境調用javascript函數來生成myfile.svg?

小唯快跑啊 2023-07-29 13:46:15
在以特定方位角編程繪制 SVG 圖標的幫助下?,我有這個 javascript 片段,可以在我的 HTML 頁面中繪制SVG。效果很好??梢栽?Windows 環境(可能是批處理或 WinForm)中使用此 javascript 函數而不是 HTML 來創建可以保存在文件夾中的實際SVG文件嗎?例如,在 winform 中,我將執行創建 SVG 的 javascript?,并將其保存為物理路徑中的myFile.svg 。let svg = document.getElementById("icon");// Add a "line" to the SVG, with a given azimuth, radius and lengthfunction makeLine(azimuth, radius, length){? let circumference = radius * 2 * Math.PI;? // Create an SVG <circle> element? let line = document.createElementNS(svg.namespaceURI, "circle");? line.setAttribute("r", radius);? line.setAttribute("stroke-dasharray", length + ' ' + circumference);? line.setAttribute("transform", "rotate(" + azimuth + ")");? // Add it to the <svg> element? svg.appendChild(line);}let LEVEL1 = 93;makeLine(300, LEVEL1, 110);svg {? width: 100px;}circle {? fill: none;? stroke: black;? stroke-width: 16;}<svg id="icon" viewBox="-100 -100 200 200"></svg>
查看完整描述

1 回答

?
一只甜甜圈

TA貢獻1836條經驗 獲得超5個贊

在 Windows 窗體項目中添加一個WebBrowser組件到您的窗體中,然后您可以javascript像下面這樣運行:


  private void Form1_Load(object sender, EventArgs e)

    {

        webBrowser1.DocumentText =

            "<html><head><script>" +

            @"function makeLine(azimuth, radius, length)

                {

                  var svg = document.getElementById('icon');

                  let circumference = radius * 2 * Math.PI;

                  

                  let line = document.createElementNS(svg.namespaceURI, 'circle');

                  line.setAttribute('r', radius);

                  line.setAttribute('stroke-dasharray', length + ' ' + circumference);

                  line.setAttribute('transform', 'rotate(' + azimuth + ')');

                  svg.appendChild(line);

                  return svg.outterHtml; //Note: this return line should be added to your code 

                }"

            + "</script></head><body><svg id=\"icon\" viewBox=\"-100 -100 200 200\"></svg></body></html>";

    }


    private void button1_Click(object sender, EventArgs e)

    {

        var result = webBrowser1.Document.InvokeScript("makeLine", new object[] { 300, 93, 110 });

        var svg = "<?xml version=\"1.0\" ?><!DOCTYPE svg  PUBLIC '-//W3C//DTD SVG 1.1//EN'  'http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd'>";

        File.WriteAllText("C:\\a.svg", svg + result.ToString());

    }


查看完整回答
反對 回復 2023-07-29
  • 1 回答
  • 0 關注
  • 122 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號