相关文章推荐
怕考试的木耳  ·  软件分享库合集链接汇总推荐_蓝奏云软件分享链 ...·  5 月前    · 
精明的日记本  ·  江西省发布第三批非法集资严重失信人名单 ...·  1 年前    · 
奔放的梨子  ·  Creating Word ...·  2 年前    · 
奔跑的苦咖啡  ·  地藏菩萨本愿经讲记(第十三卷)·  2 年前    · 
愤怒的菠萝  ·  异兽魔都(林田球创作的系列漫画)_搜狗百科·  2 年前    · 
Code  ›  Batik将SVG转换为JPEG开发者社区
svg
https://cloud.tencent.com/developer/ask/sof/347867
买醉的石榴
1 年前
首页
学习
活动
专区
工具
TVP 最新优惠活动
返回腾讯云官网
提问

问 Batik将SVG转换为JPEG

Stack Overflow用户
提问于 2019-03-18 14:23:08
EN
代码语言: javascript
复制
JPEGTranscoder transcoder = new JPEGTranscoder();
String urlPath = "D:/CRD_Material/Scheme/scheme-2.svg";
String s1 = "<svg width='350' height='450' xmlns='http://www.w3.org/2000/svg'  xmlns:xlink='http://www.w3.org/1999/xlink'>"
            + "<!-- Created with SVG-edit - http://svg-edit.googlecode.com/ -->  "
            + "<g><title>Layer 1</title> "
            + " <rect fill='none' stroke='#000000' stroke-width='2' stroke-linejoin='none' stroke-linecap='none' x='18' y='23' width='213' height='352' id='svg_6'/>"
            + "   <line fill='none' stroke='#000000' stroke-width='2' stroke-linejoin='none' stroke-linecap='none' x1='17' y1='336' x2='230' y2='336' id='svg_7'/>"
            + "   <line fill='none' stroke='#000000' stroke-width='2' stroke-linejoin='none' stroke-linecap='none' x1='20' y1='58' x2='231' y2='58' id='svg_8' stroke-dasharray='2,2'/>"
            + "   <rect id='svg_3' height='65' width='181' y='74' x='31' stroke-width='2' stroke='#000000' fill='#0'/>  </g> </svg>";
FileWriter writer = new FileWriter("D:/PDFBox/test.svg");
writer.write(s1);
writer.close();
transcoder.addTranscodingHint(JPEGTranscoder.KEY_QUALITY, new Float(1.0));
TranscoderInput input = new TranscoderInput(new FileInputStream("D:/PDFBox/test.svg"));
OutputStream ostream = new FileOutputStream("D:/PDFBox/out.jpg");
TranscoderOutput output = new TranscoderOutput(ostream);
transcoder.transcode(input, output);
ostream.close();
System.exit(0);

这是我的代码,我想将SVG字符串转换为JPEG图像。在运行这段代码时,我得到了以下错误:

代码语言: javascript
复制
org.w3c.dom.DOMException: <unknown>:
The attribute "stroke-linecap" represents an invalid CSS value ("none").
Original message:
The "none" identifier is not a valid value for the "stroke-linecap" property

谁来帮帮我..。提前感谢

1 223 0 票数 0
EN
java
svg
jpeg
batik

回答 1

Stack Overflow用户

回答已采纳

发布于 2019-03-18 16:12:05

stroke-linecap 的唯一有效值是 butt 、 round 和 square ,请参阅例如 here 。默认值为 butt 。因此,要么将 none 更改为其中之一,要么随处删除 stroke-linecap='none' 段。

您的svg代码在 stroke-linejoin 方面也有类似的问题,请参阅有效值 here 。

最后, fill='#0' 也是错误的。如果您想要黑色,请使用 fill='#000000' 或 fill='black' 。

因此,新字符串可以是

代码语言: javascript
复制
String s1 = "<svg width='350' height='450' xmlns='http://www.w3.org/2000/svg'  xmlns:xlink='http://www.w3.org/1999/xlink'>"
 
推荐文章
怕考试的木耳  ·  软件分享库合集链接汇总推荐_蓝奏云软件分享链接网站汇总手机 - 骑士助手
5 月前
精明的日记本  ·  江西省发布第三批非法集资严重失信人名单 _ 防范金融风险 _ 南昌县人民政府
1 年前
奔放的梨子  ·  Creating Word Application using Excel VBA: Run-time error '429': ActiveX component can't create obje
2 年前
奔跑的苦咖啡  ·  地藏菩萨本愿经讲记(第十三卷)
2 年前
愤怒的菠萝  ·  异兽魔都(林田球创作的系列漫画)_搜狗百科
2 年前
今天看啥   ·   Py中国   ·   codingpro   ·   小百科   ·   link之家   ·   卧龙AI搜索
删除内容请联系邮箱 2879853325@qq.com
Code - 代码工具平台
© 2024 ~ 沪ICP备11025650号