Javaを使用していくつかのイメージを大きなイメージに結合しようとしています。渡されるイメージは、すべて高さが127×幅293です。アイデアは、いくつかのイメージがメソッドに渡され、メソッドがイメージを取得し、イメージを別の大きなイメージに構築するというものです。大きな画像には、合計12の可能な画像を、より大きな画像に入力し、均等に間隔を置いて入力することができます(2行6画像、重複なし)。渡される画像が12枚未満の場合は、最初の領域だけが空白になり、残りの画像は白くなります。これは背景が白くなるためです。プログラムを実行すると、大きな画像が印刷されますが、渡される画像の数に関係なく、左上の最初の画像を表示する最初のスペースのみが塗り潰されます。背景も意図した白い背景の代わりにピンク色です。私はJavaの初心者なので、これらの学習の苦労のいくつかを試してみようとしています。どのように私の問題を解決することができるかもしれないかについてのアドバイス? (コードは参考のために下にコピーされています)ありがとう!Java複数のイメージを重複することなく1つの大きなイメージに結合する
public class ImagesCombine {
public String BuildImgs (File[] imgs)throws IOException {
int arsize = imgs.length;
File path = new File("Z:/JAVAFiles/Images/");
BufferedImage page = new BufferedImage(620,900,BufferedImage.TYPE_INT_ARGB);
Graphics2D paint;
paint = page.createGraphics();
paint.setPaint(Color.WHITE);
paint.fillRect (0, 0, page.getWidth(), page.getHeight());
paint.setBackground(Color.WHITE);
String tmpname = "";
for (int i=0;i<imgs.length;i++){
if(i==0){
Image img0 = ImageIO.read(new File(path, imgs[i].getName()));
paint.drawImage(img0,0,0,null);
paint.dispose();
}
if(i==1){
Image img1 = ImageIO.read(new File(path, imgs[i].getName()));
paint.drawImage(img1,323,0,null);
paint.dispose();
}
if(i==2){
Image img2 = ImageIO.read(new File(path, imgs[i].getName()));
paint.drawImage(img2,0,142,null);
paint.dispose();
}
if(i==3){
BufferedImage img3 = ImageIO.read(new File(path, imgs[i].getName()));
paint.drawImage(img3,323,142,null);
paint.dispose();
}
if(i==4){
BufferedImage img4 = ImageIO.read(new File(path, imgs[i].getName()));
paint.drawImage(img4,0,284,null);
paint.dispose();
}
if(i==5){
BufferedImage img5 = ImageIO.read(new File(path, imgs[i].getName()));
paint.drawImage(img5,323,284,null);
paint.dispose();
}
if(i==6){
BufferedImage img6 = ImageIO.read(new File(path, imgs[i].getName()));
paint.drawImage(img6,0,426,null);
paint.dispose();
}
if(i==7){
BufferedImage img7 = ImageIO.read(new File(path, imgs[i].getName()));
paint.drawImage(img7,323,426,null);
paint.dispose();
}
if(i==8){
BufferedImage img8 = ImageIO.read(new File(path, imgs[i].getName()));
paint.drawImage(img8,0,568,null);
paint.dispose();
}
if(i==9){
BufferedImage img9 = ImageIO.read(new File(path, imgs[i].getName()));
paint.drawImage(img9,323,568,null);
paint.dispose();
}
if(i==10){
BufferedImage img10 = ImageIO.read(new File(path, imgs[i].getName()));
paint.drawImage(img10,0,710,null);
paint.dispose();
}
if(i==11){
BufferedImage img11 = ImageIO.read(new File(path, imgs[i].getName()));
paint.drawImage(img11,323,710,null);
paint.dispose();
}
}
String outpath = "Z:\\JAVAFiles\\" + imgs[0].getName().substring(0,16) + ".jpg";
OutputStream outfile = new FileOutputStream(outpath);
JPEGImageEncoder encoder2 = JPEGCodec.createJPEGEncoder(outfile);
encoder2.encode(page);
outfile.close();
return("Success");
}
}
最初の3つの画像にタイプイメージが使用されていますが、他のすべてのイメージではbufferedimageタイプが使用されています。これは特定の理由で行われますか? –