(Q/Aへのリンク:Merging two images)(ごめんなさい、これは奇妙な音ですが、もともと「回答」の下に投稿されました。画像の結合エラー
私は、サンプルコードを含み、100以上の投票数/好きなものがあればstackoverflowにあるものすべてを使用しています。ImageIOがスローするものはすべてIOException私はかなり正直にコーディングに新しいです、私はそれをやってきました...私は最初の4つのものが、レゴの嵐に似た単純なブロックプログラミング言語であるスクラッチと呼ばれるものであると信じています。ロボット1。とにかく、3年前、私はついにミニクラフトを改造してJavaに深く入りました。私はまだjavaのにすぎもらっていない:(し、それらを検索しようとしているにもかかわらずであるかの例外を除い全くわからないです。
public void registerIcons(IconRegister iconRegister)
{
File path = new File("mymod:"); // base path of the images
// load source images
BufferedImage core = ImageIO.read(new File(path, "cores/CoreOak.png"));
BufferedImage cap = ImageIO.read(new File(path, "caps/CapGold.png"));
BufferedImage gem = ImageIO.read(new File(path, "overlay2.png"));
// create the new image, canvas size is the max. of both image sizes
int w = Math.max(core.getWidth(), cap.getWidth());
w = Math.max(w, gem.getWidth());
int h = Math.max(core.getHeight(), cap.getHeight());
h = Math.max(h, gem.getHeight());
BufferedImage combined = new BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB);
// paint both images, preserving the alpha channels
Graphics g = combined.getGraphics();
g.drawImage(core, 0, 0, null);
g.drawImage(cap, 0, 0, null);
g.drawImage(gem, 0, 0, null);
// Save as new image
ImageIO.write(combined, "PNG", new File(path, "wand/combined.png"));
this.itemIcon = iconRegister.registerIcon(texturePath + "combined");
}
コードがあります。例外はBufferedImageのもの、とのImageIOの下にあります。彼らは具体的に "Unhandled exception type IOException"と言っていますが、それはマイクロフトの問題であるかどうかはわかりませんが、一般的にjavaという意味では、この人は私にそれが広すぎるために怒鳴りました。私はそれが含まれるだろうと思っていた。