基于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)圖片的資料請(qǐng)關(guān)注好吧啦網(wǎng)其它相關(guān)文章!
相關(guān)文章:
1. ASP 信息提示函數(shù)并作返回或者轉(zhuǎn)向2. asp(vbs)Rs.Open和Conn.Execute的詳解和區(qū)別及&H0001的說(shuō)明3. CSS hack用法案例詳解4. PHP設(shè)計(jì)模式中工廠模式深入詳解5. 用css截取字符的幾種方法詳解(css排版隱藏溢出文本)6. asp中response.write("中文")或者js中文亂碼問(wèn)題7. ASP.NET MVC遍歷驗(yàn)證ModelState的錯(cuò)誤信息8. ThinkPHP5實(shí)現(xiàn)JWT Token認(rèn)證的過(guò)程(親測(cè)可用)9. ASP 處理JSON數(shù)據(jù)的實(shí)現(xiàn)代碼10. .NET中l(wèi)ambda表達(dá)式合并問(wèn)題及解決方法
