0

我目前正在开发一个使用 J/Link (MathLink) 的应用程序。但是,我在使用 KernelLink.evaluateToImage() 函数时遇到了一些问题。

我目前的代码是:

byte[] gifData = kl.evaluateToImage("Plot[x,{x,0,1}]",0,0);
            if (gifData != null) {
                BufferedImage img = ImageIO.read(new ByteArrayInputStream(gifData));
                int w = img.getWidth();
                int h = img.getHeight();
                BufferedImage bi = new BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB);
                Graphics g = bi.getGraphics();
                g.drawImage(img, 0, 0, null);
            }
            else {
                System.out.println("Not a valid Graphics Expression.");
            }

我总是输入 else 子句,因为 evaluateToImage 总是以某种方式返回 null ......

我启动了内核:

kl = MathLinkFactory.createKernelLink("-linkmode launch -linkname 'math -mathlink'");

你能帮我解决这个问题吗?最好的问候 NikNak

4

1 回答 1

0

解决方案是使用 evaluateToTypeset() 函数。正确的代码必须是:

byte[] gifData = mathLink.evaluateToTypeset(mathInput, 0, true);

                    FileOutputStream fileStream = new FileOutputStream(new File("/../1.gif"));
                    fileStream.write(gifData);
                    fileStream.close();
于 2014-09-06T12:11:57.327 回答