cynest-java

          My Links

          Blog Stats

          常用鏈接

          留言簿(1)

          隨筆檔案

          文章分類

          鏈接

          搜索

          最新評論

          閱讀排行榜

          評論排行榜

          [導入]Batik之SVGGraphics2D生成SVG

          在Java平臺上,通過java.awt.Graphics2D抽象類來實現圖形功能,該類提供了諸如

          drawRect,fillRect,以及drawString等方法。而Batik的SVGGraphics2D是一個專門的工具

          ,用來生成SVG文本內容而不是在屏幕上顯示或打印。

          SVGGraphics2D提供了如下特點的功能

          1、允許應用程序將圖形輸出成SVG格式
          2、輸出為SVG的過程不需要修改任何圖形代碼
          3、提供給用戶DOM API功能來處理產生的文檔

          生成SVG的三個步驟:
          1、創建org.w3c.dom.Document的實例,生成器利用它建立XML內容。創建一個SVG生

          成器則使用Document實例。

          // Get a DOMImplementation
          DOMImplementation domImpl =
          ??? GenericDOMImplementation.getDOMImplementation();

          // Create an instance of org.w3c.dom.Document
          Document document = domImpl.createDocument(null, "svg", null);

          // Create an instance of the SVG Generator
          SVGGraphics2D svgGenerator = new SVGGraphics2D(document);

          2、在SVG生成器上調用表現代碼,如paint方法

          // Ask the test to render into the SVG Graphics2D implementation
          TestSVGGen test = new TestSVGGen();
          test.paint(svgGenerator);

          3、輸出SVG內容,生成器可以通過任何一個java.io.Writer把內容stream出來。

          // Finally, stream out SVG to the standard output using UTF-8
          // character to byte encoding
          boolean useCSS = true; // we want to use CSS style attribute
          Writer out = new OutputStreamWriter(System.out, "UTF-8");
          svgGenerator.stream(out, useCSS);

          注:SVG在表達屬性時可以由兩種方式,XML屬性和CSS方式。


          文章來源:http://cynest.cn/drupal/?q=node/612

          posted on 2006-02-14 15:38 cyqian 閱讀(1954) 評論(0)  編輯  收藏


          只有注冊用戶登錄后才能發表評論。


          網站導航:
           
          主站蜘蛛池模板: 准格尔旗| 奉节县| 民县| 永修县| 龙山县| 华亭县| 汝阳县| 天柱县| 化州市| 承德县| 涞水县| 锡林浩特市| 灵宝市| 凌云县| 丹江口市| 沂水县| 盱眙县| 关岭| 扎囊县| 英山县| 金堂县| 修水县| 盐城市| 民勤县| 江永县| 德惠市| 普洱| 鱼台县| 垦利县| 新营市| 丽水市| 兴海县| 临猗县| 长汀县| 江孜县| 黄龙县| 黄骅市| 饶河县| 乐安县| 民县| 上高县|