画像を複数出力させると
二つのプロットを連続して受け取ってみる。
import java.awt.image.BufferedImage; import java.io.*; import javax.imageio.ImageIO; public class GnuplotUser5 { private static final String GNUPLOT = "/usr/bin/gnuplot"; public static void main(String[] args) throws IOException, InterruptedException { Process p = new ProcessBuilder(GNUPLOT, "-").start(); PrintWriter out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(p.getOutputStream()))); BufferedInputStream in = new BufferedInputStream(p.getInputStream()); out.println("set terminal png"); out.println("plot sin(x)"); out.println("set output"); out.flush(); BufferedImage image1 = ImageIO.read(in); System.err.println(image1); out.println("set terminal png"); out.println("plot sin(x+pi/10)"); out.println("set output"); out.flush(); BufferedImage image2 = ImageIO.read(in); System.err.println(image2); out.close(); in.close(); p.waitFor(); } }
$ java GnuplotUser5 BufferedImage@ffc3eb: type = 13 IndexColorModel: #pixelBits = 8 numComponents = 3 color space = java.awt.color.ICC_ColorSpace@1978933 transparency = 1 transInde x = -1 has alpha = false isAlphaPre = false ByteInterleavedRaster: width = 640 height = 480 #numDataElements 1 dataOff[0] = 0 null
一つ目は既述と同じなので当然うまく受け取れている。
しかし二つ目はnullが返されており、
うまく画像オブジェクトを得られていないことが分かる。