Image to Buffer

  private byte[] getPhoto()
    throws Exception {
    final String ICON_EXT = "png";
    String file ="D:\\workspace\\OSL\\trunk\\learning-tool\\Web\\public_html\\images\\chart.png";

    BufferedImage orgImage = ImageIO.read(new FileInputStream(file));
    ByteArrayOutputStream o = new ByteArrayOutputStream();
    ImageIO.write(orgImage, ICON_EXT, o);

    return o.toByteArray();

  }

你可能感兴趣的:(java,image)