import java.awt.Graphics;
import java.awt.Image;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import javax.imageio.ImageIO;
import javax.swing.ImageIcon;
import javax.swing.JFileChooser;
public class Main {
/**
* @param args
* @throws IOException
*/
public static void main(String[] args) throws IOException {
// ファイル指定
File file = new File("ファイル指定");
JFileChooser chooser = new JFileChooser();
// icon抽出
ImageIcon icon = (ImageIcon) chooser.getIcon(file);
// 保存先ファイル
String ext = file.getAbsoluteFile() + ".png";
// 出力
ImageIO.write(createBufferedImage(icon.getImage()), "png",
new File(ext));
}
public static BufferedImage createBufferedImage(Image img) {
BufferedImage bimg = new BufferedImage(img.getWidth(null), img.getHeight(null), BufferedImage.TYPE_INT_RGB);
Graphics g = bimg.getGraphics();
g.drawImage(img, 0, 0, null);
g.dispose();
return bimg;
}
}
取りあえず書いてみました。
が、上記だとイメージが保存までできるのですが、なぜか正しいアイコンではないです。
それは別途究明する必要がありますね。
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
退会済みユーザー
2015/12/07 00:45
退会済みユーザー
2018/04/25 04:14