0

当我尝试使用 org.apache.batik.apps.rasterizer.SVGConverter 将 svg 文件转换为 png 图像时,图像被切断。下面提到了java代码。

SVGConverter svgConverter = new SVGConverter();
svgConverter.setDestinationType(DestinationType.PNG);
svgConverter.setSources(new String[]{ new File(svgsource).toURL().toString() });
svgConverter.setDst(new File(imgDest));
svgConverter.execute();

另请查找 SVG 文件的代码。

<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
 <line x1="10" y1="0" x2="10" y2="500" style="stroke: #000000; stroke-width: 1;" />
 <line x1="10" y1="500" x2="500" y2="500" style="stroke: #000000; stroke-width: 1;" />

<text x="0" y="520"  style="stroke: none; fill: #000000; font-family: Arial; font-size: 10px;" >3PA</text>
<line x1="100" y1="0" x2="100" y2="500" style="stroke: darkgray; stroke-width: 0.2" />
<text x="100" y="520"  style="stroke: none; fill: #000000; font-family: Arial; font-size: 10px;" >3PB</text>
<line x1="200" y1="0" x2="200" y2="500" style="stroke: darkgray; stroke-width: 0.2" />
<text x="200" y="520"  style="stroke: none; fill: #000000; font-family: Arial; font-size: 10px;" >3PC</text>
<line x1="300" y1="0" x2="300" y2="500" style="stroke: darkgray; stroke-width: 0.2" />
<text x="300" y="520"  style="stroke: none; fill: #000000; font-family: Arial; font-size: 10px;" >4PA</text>
<line x1="400" y1="0" x2="400" y2="500" style="stroke: darkgray; stroke-width: 0.2" />
<text x="400" y="520"  style="stroke: none; fill: #000000; font-family: Arial; font-size: 10px;" >4PB</text>

<line x1="10" y1="100" x2="500" y2="100" style="stroke: darkgray; stroke-width: 0.2" />
<line x1="10" y1="200" x2="500" y2="200" style="stroke: darkgray; stroke-width: 0.2" />
<line x1="10" y1="300" x2="500" y2="300" style="stroke: darkgray; stroke-width: 0.2" />
<line x1="10" y1="400" x2="500" y2="400" style="stroke: darkgray; stroke-width: 0.2" />


<line x1="10" y1="450" x2="100" y2="450" 
      style="stroke:yellow; stroke-width:5; stroke-linejoin:miter" />


<line x1="100" y1="450" x2="200" y2="330" 
      style="stroke:yellow; stroke-width:5; stroke-linejoin:miter" />


<line x1="200" y1="330" x2="300" y2="380" 
      style="stroke:yellow; stroke-width:5; stroke-linejoin:miter" />



<polygon points="300,380 400,320 400,360 300,380"
    style="fill:paleturquoise; stroke: darkturquoise; stroke-width:1" />


<line x1="100" y1="420" x2="100" y2="460" 
    style="fill:darkturquoise; stroke: darkturquoise; stroke-width:7" />


<line x1="200" y1="340" x2="200" y2="380" 
      style="stroke:darkturquoise; stroke: darkturquoise; stroke-width:7" />

<line x1="300" y1="310" x2="300" y2="350" 
      style="stroke:darkturquoise; stroke: darkturquoise; stroke-width:7" />


<line x1="400" y1="320" x2="400" y2="360" 
      style="stroke:darkturquoise; stroke: darkturquoise; stroke-width:7" />


<text x="400" y="320"  style="stroke: none; fill: #000000; font-family: Arial; font-size: 10px;" >320</text>
<text x="400" y="360"  style="stroke: none; fill: #000000; font-family: Arial; font-size: 10px;" >360</text>




</svg>

Online_Editor_image.JPG 另请查找由 Java 代码生成 的在线编辑器图像在此处输入图像描述和 png 文件。

请帮助我获得完整的图像作为在线图像编辑器。

4

1 回答 1

0

在 svg 标签中提及高度和宽度,例如

<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="600" height="600">

于 2011-09-26T12:29:11.697 回答