Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/328.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java J/Link(MathLink)-evaluateToImage()始终返回null_Java_Image_Evaluate_Mathlink_Jlink - Fatal编程技术网

Java J/Link(MathLink)-evaluateToImage()始终返回null

Java J/Link(MathLink)-evaluateToImage()始终返回null,java,image,evaluate,mathlink,jlink,Java,Image,Evaluate,Mathlink,Jlink,我目前正在开发一个使用J/Link-MathLink的应用程序。 但是,我在使用KernelLink.evaluateToImage函数时遇到了一些问题 我目前的代码是: byte[] gifData = kl.evaluateToImage("Plot[x,{x,0,1}]",0,0); if (gifData != null) { BufferedImage img = ImageIO.read(new ByteArrayInputSt

我目前正在开发一个使用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

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

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

                    FileOutputStream fileStream = new FileOutputStream(new File("/../1.gif"));
                    fileStream.write(gifData);
                    fileStream.close();