java mathematica_用Java获取Mathematica图像
我試圖使用J / Link從Mathematica獲取圖像到
Java.我可以在Mathematica中打印圖像,如下所示:
Print[ Graphics[Raster[ img[[1]] ], AspectRatio->Automatic, ImageSize->530 ] ];
我試過以各種方式從Mathematica函數(shù)返回數(shù)據(jù):
Return [ Image[Graphics[Raster[ img[[1]] ], AspectRatio->Automatic, ImageSize->530 ]] ];
Return [ Graphics[Raster[ img[[1]] ], AspectRatio->Automatic, ImageSize->530 ] ];
Return [ Raster[ note1[[1]] ] ];
Return [ note1[[1]] ];
我的Java代碼:
ml.evaluate("tmp = renderImageGeneric[" + sampleId + ", noteText," + sizeX + "," + sizeY + ", margin," + dpi + "," + lineStep + "," + tabStep + "," + ligatureMatch + "," + maxLigHeightDiff + "," + mmSearch + "," + highToLowGap + "," + lowToHighGap + "," + wordBaselineVariance + "," + debugFlag + "]");
ml.discardAnswer();
byte[] res = ml.evaluateToImage("tmp", 0, 0);
ByteArrayInputStream strm = new ByteArrayInputStream(res);
BufferedImage imag = ImageIO.read(strm);
//BufferedImage imag = ImageIO.read(new InputStream(res));
if(imag != null) {
ImageIO.write(imag, "png", new File("/Users/Rebecca/","test.png"));
}else {
System.out.println("image is null");
}
調(diào)試時,我在res中得到一個大字節(jié)數(shù)組.圖像確實被保存,但它是空白的(即白色圖像).
如果我只返回一個字符串(“藍色”),則會保存帶有藍色字符串的圖像.
我假設(shè)我需要在renderImageGeneric中返回不同的東西,但我無法弄清楚是什么.
謝謝!
總結(jié)
以上是生活随笔為你收集整理的java mathematica_用Java获取Mathematica图像的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Mac上安装PL/SQL Develop
- 下一篇: java中io流是类吗_Java中的IO