コード例 #1
0
  private void writeImageFile(BufferedImage image, File imageFile) {
    String filename = imageFile.toString();
    String extension = filename.substring(filename.lastIndexOf('.') + 1, filename.length());
    assert extension.equalsIgnoreCase("png") || extension.equalsIgnoreCase("gif");
    try {
      ImageIO.write(image, extension.toLowerCase(), imageFile);

    } catch (Exception e) {
      Cheshire.exit("Could not write image to file %s", imageFile.toString());
    }
  }
コード例 #2
0
  private BufferedImage readImageFile(File imageFile) {
    ImageIcon icon = null;
    try {
      icon = new ImageIcon(imageFile.toURI().toURL());
    } catch (Exception e) {
      Cheshire.exit("Could not read image file %s", imageFile.toString());
    }
    Image image = icon.getImage();

    BufferedImage buffImage =
        new BufferedImage(image.getWidth(null), image.getHeight(null), BufferedImage.TYPE_INT_ARGB);

    Graphics g = buffImage.getGraphics();
    g.drawImage(image, 0, 0, null);

    return buffImage;
  }