如何在Java中Stich to Image对象

我有一个场景,我从我的地图服务器获得了一些瓷砖(例如12)。 现在对于缓冲和离线function,我需要再次将它们连接起来,这样我们就必须处理1个单个图像对象而不是12个。我试过没有JAI,我的代码在下面。

package imagemerge; import java.awt.*; import java.awt.image.*; import java.awt.event.*; public class ImageSticher extends WindowAdapter { Image tile1; Image tile2; Image result; ColorModel colorModel; int width,height,widthr,heightr; //int t1,t2; int t12[]; public ImageSticher() { } public ImageSticher (Image img1,Image img2,int w,int h) { tile1=img1; tile2=img2; width=w; height=h; colorModel=ColorModel.getRGBdefault(); } public Image horizontalStich() throws Exception { widthr=width*2; heightr=height; t12=new int[widthr * heightr]; int t1[]=new int[width*height]; PixelGrabber p1 =new PixelGrabber(tile1, 0, 0, width, height, t1, 0, width); p1.grabPixels(); int t2[]=new int[width*height]; PixelGrabber p2 =new PixelGrabber(tile2, 0, 0, width, height, t1, 0, width); p2.grabPixels(); int y, x, rp, rpi; int red1, red2, redr; int green1, green2, greenr; int blue1, blue2, bluer; int alpha1, alpha2, alphar; for(y=0;y<heightr;y++) { for(x=0;x<widthr;x++) { //System.out.println(x); rpi=y*widthr+x; // index of resulting pixel; rp=0; //initializing resulting pixel System.out.println(rpi); if(x> 8) & 0x00ff; red1=(t1[rpi] >> 16) & 0x00ff; alpha1 = (t1[rpi] >> 24) & 0x00ff; redr = (int)(red1 * 1.0); // copying red band pixel into redresult,,,,1.0 is the alpha valye redr = (redr 255)?(255):(redr)); greenr = (int)(green1 * 1.0); // redr = (int)(red1 * 1.0); // greenr = (greenr 255)?(255):(greenr)); bluer = (int)(blue1 * 1.0); bluer = (bluer 255)?(255):(bluer)); alphar = 255; //resulting pixel computed rp = (((((alphar << 8) + (redr & 0x0ff)) << 8) + (greenr & 0x0ff)) <> 8) & 0x00ff; red2=(t2[rpi] >> 16) & 0x00ff; alpha2 = (t2[rpi] >> 24) & 0x00ff; redr = (int)(red2 * 1.0); // copying red band pixel into redresult,,,,1.0 is the alpha valye redr = (redr 255)?(255):(redr)); greenr = (int)(green2 * 1.0); // redr = (int)(red2 * 1.0); // greenr = (greenr 255)?(255):(greenr)); bluer = (int)(blue2 * 1.0); bluer = (bluer 255)?(255):(bluer)); alphar = 255; //resulting pixel computed rp = (((((alphar << 8) + (redr & 0x0ff)) << 8) + (greenr & 0x0ff)) << 8) + (bluer & 0x0ff); } t12[rpi] = rp; // copying resulting pixel in the result int array which will be converted to image } } MemoryImageSource mis; if (t12!=null) { mis = new MemoryImageSource(widthr, heightr, colorModel, t12, 0, widthr); result = Toolkit.getDefaultToolkit().createImage(mis); return result; } return null; } } 

现在检查我的理论我m trying to join or stich two tiles horizontaly but i得到错误:

java.lang.ArrayIndexOutOfBoundsException:90000 at imagemerge.ImageSticher.horizo​​ntalStich(ImageSticher.java:69)at imageStream.ImageStream.getImage(ImageStream.java:75)at imageStream.ImageStream.main(ImageStream.java:28)

是否存在某种限制,因为当水平放置300 x 300的两个图像时,这意味着生成的图像将是600 x 300 …这将使180000索引大小但它在90000处给出错误,我在这里做错了什么

rpi是结果像素的索引,而不是t1源图块数据中的索引,它是大小的一半。