JAVA

2017-11-28 14 views
0

을 사용하여 HTML5로 작성된 SVG를 JPG로 변환하면 Java를 사용하여 순수 SVG 코드를 JPG로 변환 할 수 있습니까? 나는 바틱 SVG를 사용하려고했지만, 회화 할 파일 경로가 필요하다. 코드 만 사용하고 싶다.JAVA

SVG 코드 :

String chart = "<svg width=\"700\" height=\"297\" aria-label=\"A chart.\" style=\"overflow: hidden;\"><defs id=\"defs\"><clipPath id=\"_ABSTRACT_RENDERER_ID_0\"><rect x=\"175\" y=\"57\" width=\"350\" height=\"184\"></rect></clipPath><filter id=\"_ABSTRACT_RENDERER_ID_1\"><feGaussianBlur in=\"SourceAlpha\" stdDeviation=\"2\"></feGaussianBlur><feOffset dx=\"1\" dy=\"1\"></feOffset><feComponentTransfer><feFuncA type=\"linear\" slope=\"0.1\"></feFuncA></feComponentTransfer><feMerge><feMergeNode></feMergeNode><feMergeNode in=\"SourceGraphic\"></feMergeNode></feMerge></filter></defs><rect x=\"0\" y=\"0\" width=\"700\" height=\"297\" stroke=\"none\" stroke-width=\"0\" fill=\"#ffffff\"></rect><g><rect x=\"538\" y=\"57\" width=\"149\" height=\"13\" stroke=\"none\" stroke-width=\"0\" fill-opacity=\"0\" fill=\"#ffffff\"></rect><g><rect x=\"538\" y=\"57\" width=\"149\" height=\"13\" stroke=\"none\" stroke-width=\"0\" fill-opacity=\"0\" fill=\"#ffffff\"></rect><g><text text-anchor=\"start\" x=\"569\" y=\"68.05\" font-family=\"Arial\" font-size=\"13\" stroke=\"none\" stroke-width=\"0\" fill=\"#222222\">Wynik</text></g><rect x=\"538\" y=\"57\" width=\"26\" height=\"13\" stroke=\"none\" stroke-width=\"0\" fill=\"#3366cc\"></rect></g></g><g><rect x=\"175\" y=\"57\" width=\"350\" height=\"184\" stroke=\"none\" stroke-width=\"0\" fill-opacity=\"0\" fill=\"#ffffff\"></rect><g clip-path=\"url(http://localhost:8080/summary#_ABSTRACT_RENDERER_ID_0)\"><g><rect x=\"175\" y=\"57\" width=\"1\" height=\"184\" stroke=\"none\" stroke-width=\"0\" fill=\"#cccccc\"></rect><rect x=\"262\" y=\"57\" width=\"1\" height=\"184\" stroke=\"none\" stroke-width=\"0\" fill=\"#cccccc\"></rect><rect x=\"350\" y=\"57\" width=\"1\" height=\"184\" stroke=\"none\" stroke-width=\"0\" fill=\"#cccccc\"></rect><rect x=\"437\" y=\"57\" width=\"1\" height=\"184\" stroke=\"none\" stroke-width=\"0\" fill=\"#cccccc\"></rect><rect x=\"524\" y=\"57\" width=\"1\" height=\"184\" stroke=\"none\" stroke-width=\"0\" fill=\"#cccccc\"></rect></g><g><rect x=\"176\" y=\"64\" width=\""+ String.valueOf(getGroupAnswer.get(0).getValue() * 5.79) +"\" height=\"23\" stroke=\"#ffa500\" stroke-width=\"1\" fill=\"#ffa500\"></rect><rect x=\"176\" y=\"101\" width=\""+ String.valueOf(getGroupAnswer.get(1).getValue() * 5.79) +"\" height=\"23\" stroke=\"#b87333\" stroke-width=\"1\" fill=\"#b87333\"></rect><rect x=\"176\" y=\"138\" width=\""+ String.valueOf(getGroupAnswer.get(2).getValue() * 5.79) +"\" height=\"22\" stroke=\"#c0c0c0\" stroke-width=\"1\" fill=\"#c0c0c0\"></rect><rect x=\"176\" y=\"174\" width=\""+ String.valueOf(getGroupAnswer.get(3).getValue() * 5.79) +"\" height=\"23\" stroke=\"#ffd700\" stroke-width=\"1\" fill=\"#ffd700\"></rect><rect x=\"176\" y=\"211\" width=\""+ String.valueOf(getGroupAnswer.get(4).getValue() * 5.79) +"\" height=\"23\" stroke=\"#e5e4e2\" stroke-width=\"1\" fill=\"#e5e4e2\"></rect></g><g><rect x=\"175\" y=\"57\" width=\"1\" height=\"184\" stroke=\"none\" stroke-width=\"0\" fill=\"#333333\"></rect></g></g><g></g><g><g><text text-anchor=\"middle\" x=\"175.5\" y=\"260.05\" font-family=\"Arial\" font-size=\"13\" stroke=\"none\" stroke-width=\"0\" fill=\"#444444\">0</text></g><g><text text-anchor=\"middle\" x=\"262.75\" y=\"260.05\" font-family=\"Arial\" font-size=\"13\" stroke=\"none\" stroke-width=\"0\" fill=\"#444444\">15</text></g><g><text text-anchor=\"middle\" x=\"350\" y=\"260.05\" font-family=\"Arial\" font-size=\"13\" stroke=\"none\" stroke-width=\"0\" fill=\"#444444\">30</text></g><g><text text-anchor=\"middle\" x=\"437.25\" y=\"260.05\" font-family=\"Arial\" font-size=\"13\" stroke=\"none\" stroke-width=\"0\" fill=\"#444444\">45</text></g><g><text text-anchor=\"middle\" x=\"524.5\" y=\"260.05\" font-family=\"Arial\" font-size=\"13\" stroke=\"none\" stroke-width=\"0\" fill=\"#444444\">60</text></g><g><text text-anchor=\"end\" x=\"162\" y=\"80.35\" font-family=\"Arial\" font-size=\"13\" stroke=\"none\" stroke-width=\"0\" fill=\"#222222\">TEST4</text></g><g><text text-anchor=\"end\" x=\"162\" y=\"116.95\" font-family=\"Arial\" font-size=\"13\" stroke=\"none\" stroke-width=\"0\" fill=\"#222222\">TEST1</text></g><g><text text-anchor=\"end\" x=\"162\" y=\"153.55\" font-family=\"Arial\" font-size=\"13\" stroke=\"none\" stroke-width=\"0\" fill=\"#222222\">TEST5</text></g><g><text text-anchor=\"end\" x=\"162\" y=\"190.15\" font-family=\"Arial\" font-size=\"13\" stroke=\"none\" stroke-width=\"0\" fill=\"#222222\">TEST3</text></g><g><text text-anchor=\"end\" x=\"162\" y=\"226.75000000000003\" font-family=\"Arial\" font-size=\"13\" stroke=\"none\" stroke-width=\"0\" fill=\"#222222\">TEST2</text></g></g></g><g><g><text text-anchor=\"middle\" x=\"350\" y=\"284.4562\" font-family=\"Arial\" font-size=\"13\" font-style=\"italic\" stroke=\"none\" stroke-width=\"0\" fill=\"#222222\">Wynik całkowity</text><rect x=\"175\" y=\"273.4062\" width=\"350\" height=\"13\" stroke=\"none\" stroke-width=\"0\" fill-opacity=\"0\" fill=\"#ffffff\"></rect></g></g><g></g></svg>"; 
+0

가능한 중복 https://stackoverflow.com/questions/4437806/convert-html-to-image-in-byte-array-java –

답변

2

당신은의 InputStream로 문자열을 변환 할 수 있습니다

String chart = "<svg width=\"700\..."; 
InputStream stream = new ByteArrayInputStream(chart.getBytes(StandardCharsets.UTF_8.name())); 

및 TranscoderInput 생성자에 그 전달 :

TranscoderInput input = new TranscoderInput(stream); 
+0

TranscoderInput? 죄송하지만 자바와이 라이브러리에 익숙하지 않습니다. 더 설명 할 수 있습니까? –

+0

바틱을 사용하여 SVG를 jpg로 변환했다고하셨습니다. TranscoderInput은 입력 (SVG)을 변환 할 객체입니다. 당신은 http://www.java2s.com/Code/Java/XML/SVGtoJPEG.htm –

+0

예제에서 새로운 FileInputStream ("rectangles.svg") 대신에 새로운 ByteArrayInputStream (chart.getBytes (StandardCharsets.UTF_8.name())) .svg 파일 대신 문자열에서 SVG 데이터를 가져옵니다. –