res.setContentType("image/png");
BufferedImage bi = new BufferedImage(WIDTH, HEIGHT,BufferedImage.TYPE_INT_RGB);
//BufferedImage bi = ImageIO.read(new File("src/images/router.png"));
Graphics g = bi.getGraphics();
g.setColor(Color.WHITE);// 画框
g.fillRect(0, 0, WIDTH, HEIGHT);
g.setColor(Color.GRAY);// 画框
g.drawRect(0, 0, WIDTH-5, HEIGHT-5);
Image img = new ImageIcon("./WebRoot/images/router.png").getImage();
g.setColor(Color.RED);
g.drawImage(img,600,800,1000,1000, null);//指定位置显示图片
ImageIO.write(bi, "png", byteOutputStream);
topologyGraphics = byteOutputStream.toByteArray();
res.getOutputStream().write(topologyGraphics);
BufferedImage bi = new BufferedImage(WIDTH, HEIGHT,BufferedImage.TYPE_INT_RGB);
//BufferedImage bi = ImageIO.read(new File("src/images/router.png"));
Graphics g = bi.getGraphics();
g.setColor(Color.WHITE);// 画框
g.fillRect(0, 0, WIDTH, HEIGHT);
g.setColor(Color.GRAY);// 画框
g.drawRect(0, 0, WIDTH-5, HEIGHT-5);
Image img = new ImageIcon("./WebRoot/images/router.png").getImage();
g.setColor(Color.RED);
g.drawImage(img,600,800,1000,1000, null);//指定位置显示图片
ImageIO.write(bi, "png", byteOutputStream);
topologyGraphics = byteOutputStream.toByteArray();
res.getOutputStream().write(topologyGraphics);
这句话就不太靠谱,相对路径很不可靠,最好用绝对路径。
看你像是在Web应用中,那么也可以通过servletContext来获取绝对路径。
另外其实建议用ImageIO来读取图片,类似于:
Image img = ImageIO.read(new File("./WebRoot/images/router.png"));