基于Java的MathML轉(zhuǎn)圖片的方法(示例代碼)
Maven依賴:
<dependency><groupId>de.rototor.jeuclid</groupId><artifactId>jeuclid-core</artifactId><version>3.1.14</version></dependency>
示例:
@Testpublic 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>';//創(chuàng)建轉(zhuǎn)換器Converter converter = Converter.getInstance();//創(chuàng)建layoutContext并設(shè)置相關(guān)參數(shù)//參數(shù)設(shè)置可以參考net.sourceforge.jeuclid.context.Parameter類//參數(shù)默認(rèn)值可以參考LayoutContextImpl類構(gòu)造方法LayoutContextImpl layoutContext = (LayoutContextImpl) LayoutContextImpl.getDefaultLayoutContext();//設(shè)置公式字體大小,默認(rèn)12.0ptlayoutContext.setParameter(Parameter.MATHSIZE, 30);//設(shè)置公式顏色,默認(rèn)黑色layoutContext.setParameter(Parameter.MATHCOLOR, Color.RED);//轉(zhuǎn)換Dimension dimension = converter.convert(mathStr, new FileOutputStream('f:/1.png'), 'image/png', layoutContext);if(dimension != null){System.out.println('圖片轉(zhuǎn)換成功!高:' + dimension.getHeight() + ' 寬:' + dimension.getWidth());}}
輸出結(jié)果:
圖片轉(zhuǎn)換成功!高:70.0 寬:149.0
轉(zhuǎn)換結(jié)果如下:
關(guān)于outFileType參數(shù)的取值,支持以下幾種:
image/pngimage/vnd.wap.wbmpimage/x-pngimage/jpegimage/tiffimage/bmpimage/gif
以上就是基于Java的MathML轉(zhuǎn)圖片的方法(示例代碼)的詳細(xì)內(nèi)容,更多關(guān)于Java MathML轉(zhuǎn)圖片的資料請關(guān)注好吧啦網(wǎng)其它相關(guān)文章!
相關(guān)文章:
1. ASP中解決“對象關(guān)閉時,不允許操作。”的詭異問題……2. ASP刪除img標(biāo)簽的style屬性只保留src的正則函數(shù)3. xpath簡介_動力節(jié)點Java學(xué)院整理4. XML解析錯誤:未組織好 的解決辦法5. PHP設(shè)計模式中工廠模式深入詳解6. 使用Spry輕松將XML數(shù)據(jù)顯示到HTML頁的方法7. 告別AJAX實現(xiàn)無刷新提交表單8. 詳解盒子端CSS動畫性能提升9. ASP基礎(chǔ)入門第三篇(ASP腳本基礎(chǔ))10. 在JSP中使用formatNumber控制要顯示的小數(shù)位數(shù)方法
