Maven依賴:
<dependency>
<groupId>de.rototor.jeuclid</groupId>
<artifactId>jeuclid-core</artifactId>
<version>3.1.14</version>
</dependency>
示例:
@Test
public void testMathMlToImg() throws IOException {
//MathML字串
String mathStr = "<math xmlns=\"http://www.w3.org/1998/Math/MathML\">\n" +
" <mi>f</mi>\n" +
" <mo>(</mo>\n" +
" <mi>x</mi>\n" +
" <mo>)</mo>\n" +
" <mo>></mo>\n" +
" <mfrac>\n" +
" <msqrt>\n" +
" <mn>2</mn>\n" +
" </msqrt>\n" +
" <mn>8</mn>\n" +
" </mfrac>\n" +
" <mo>+</mo>\n" +
" <mn>1</mn>\n" +
" </math>";
//創建轉換器
Converter converter = Converter.getInstance();
//創建layoutContext并設定相關引數
//引數設定可以參考net.sourceforge.jeuclid.context.Parameter類
//引數默認值可以參考LayoutContextImpl類構造方法
LayoutContextImpl layoutContext = (LayoutContextImpl) LayoutContextImpl.getDefaultLayoutContext();
//設定公式字體大小,默認12.0pt
layoutContext.setParameter(Parameter.MATHSIZE, 30);
//設定公式顏色,默認黑色
layoutContext.setParameter(Parameter.MATHCOLOR, Color.RED);
//轉換
Dimension dimension = converter.convert(mathStr, new FileOutputStream("f:/1.png"), "image/png", layoutContext);
if(dimension != null){
System.out.println("圖片轉換成功!高:" + dimension.getHeight() + " 寬:" + dimension.getWidth());
}
}
輸出結果:
圖片轉換成功!高:70.0 寬:149.0
轉換結果如下:

關于outFileType引數的取值,支持以下幾種:
image/png
image/vnd.wap.wbmp
image/x-png
image/jpeg
image/tiff
image/bmp
image/gif
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/288308.html
標籤:其他
