基于Java的MathML轉圖片的方法(示例代碼)
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>';//創建轉換器Converter converter = Converter.getInstance();//創建layoutContext并設置相關參數//參數設置可以參考net.sourceforge.jeuclid.context.Parameter類//參數默認值可以參考LayoutContextImpl類構造方法LayoutContextImpl layoutContext = (LayoutContextImpl) LayoutContextImpl.getDefaultLayoutContext();//設置公式字體大小,默認12.0ptlayoutContext.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/pngimage/vnd.wap.wbmpimage/x-pngimage/jpegimage/tiffimage/bmpimage/gif
以上就是基于Java的MathML轉圖片的方法(示例代碼)的詳細內容,更多關于Java MathML轉圖片的資料請關注好吧啦網其它相關文章!
相關文章:
1. Python 實現勞拉游戲的實例代碼(四連環、重力四子棋)2. python 寫函數在一定條件下需要調用自身時的寫法說明3. Java GZip 基于內存實現壓縮和解壓的方法4. java獲取文件編碼,jsoup獲取html純文本操作5. 淺談Android Studio導出javadoc文檔操作及問題的解決6. 利用CSS制作3D動畫7. 一款功能強大的markdown編輯器tui.editor使用示例詳解8. 存儲于xml中需要的HTML轉義代碼9. jsp+servlet簡單實現上傳文件功能(保存目錄改進)10. .Net加密神器Eazfuscator.NET?2023.2?最新版使用教程
