java⽣成svg_java通过SVG导出图⽚
importjava.io.ByteArrayInputStream;importjava.io.File;importjava.io.FileOutputStream;importjava.io.IOException;importjava.io.Ou 将svg转换为png格式的图⽚
*
**/
public classtestPDF {/*** 将svg字符串转换为png
*
*@paramsvgCode svg代码
*@parampngFilePath 保存的路径
*@throwsTranscoderException svg代码异常
*@throwsIOException io错误*/
public static void convertToPng(String svgCode, String pngFilePath) throwsIOException,
TranscoderException {
File file= newFile(pngFilePath);
FileOutputStream outputStream= null;try{
outputStream= newFileOutputStream(file);
convertToPng(svgCode, outputStream);
}finally{if (outputStream != null) {try{
outputStream.close();
}catch(IOException e) {
e.printStackTrace();
}
}
}
svg图}/*** 将svgCode转换成png⽂件,直接输出到流中
*
*@paramsvgCode svg代码
*@paramoutputStream 输出流
*@throwsTranscoderException 异常
*@throwsIOException io异常*/
public static voidconvertToPng(String svgCode, OutputStream outputStream)throwsTranscoderException, IOException
{try{byte[] bytes = Bytes("utf-8");
PNGTranscoder t= newPNGTranscoder();
TranscoderInput input= new TranscoderInput(newByteArrayInputStream(bytes));
TranscoderOutput output= newTranscoderOutput(outputStream);
outputStream.flush();
}finally{if (outputStream != null) {try{
outputStream.close();
}catch(IOException e) {
e.printStackTrace();
}
}
}
}public static voidmain(String[] args) {
String outimgfilename= "d://svg.png";//String tmp_str = "Created with Highcharts 4.1.7时长(秒)⾓标互动⽀持飞字灯箱实物摆放⼝播内容提⽰压屏条场景植⼊麦标⼤屏幕⽚尾拉滚⼈名提⽰条协助播映道具植⼊产品使⽤微博互动PAD屏⽚尾鸣谢歌名条⼴告关版虚拟模型过渡⽚⽚头冠名实物模型⼴告开版笔记本背贴0k100k25k50k75k125k";
String tmp_str = "Created with Highcharts 4.1.7时长(秒)⾓标互动⽀持飞字灯箱实物摆放⼝播内容提⽰压屏条场景植⼊麦标⼤屏幕⽚尾拉滚⼈名提⽰条协助播映道具植⼊产品使⽤微博互动PAD屏⽚尾鸣谢歌名条⼴告关版虚拟模型过渡⽚⽚头冠名实物模型⼴告开版笔记本背贴0k100k25k50k75k125k";try{
convertToPng(tmp_str, outimgfilename);
}catch(IOException e) {
e.printStackTrace();
}catch(TranscoderException e) {
e.printStackTrace();
}
}
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论