Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/312.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java int[]到BuffereImage_Java_Exception_Int_Bufferedimage_Raster - Fatal编程技术网

Java int[]到BuffereImage

Java int[]到BuffereImage,java,exception,int,bufferedimage,raster,Java,Exception,Int,Bufferedimage,Raster,我正在尝试过滤图像。首先,我将RGB值放入int[][]中,然后进行过滤。 在下一步中,我必须将int[][]转换为int[],最后我想再次显示新图像。这是我的代码: int row,col,count=0; int[] pixels = new int[width*height]; while(count!=(pixels.length)){ for(row=0;row<height;row++){

我正在尝试过滤图像。首先,我将RGB值放入
int[][]
中,然后进行过滤。 在下一步中,我必须将
int[][]
转换为
int[]
,最后我想再次显示新图像。这是我的代码:

 int row,col,count=0;
          int[] pixels = new int[width*height];

            while(count!=(pixels.length)){   
                for(row=0;row<height;row++){
                     for(col=0;col<width;col++){
                         pixels[count] = imageArray[row][col];
                         count++;
                     }
                }
            }

             BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
             WritableRaster raster = (WritableRaster) image.getData();

             raster.setPixels(0,0,width,height,pixels); //The problem appear in this line
int行,列,计数=0;
int[]像素=新int[宽度*高度];
而(count!=(pixels.length)){

for(row=0;row数组在Java中是基于零的,因此

int[] array = {1,2,3};
长度为3,但最大元素引用为2和

while( count <= array.length ) {
    System.out.println( array[count] );
    ++count;
}

while(count将数组声明行更改为此
int[]像素=新的int[(宽度+1)*(高度+1)];
,查看它是否有效。文档[,int,int,int,int[])]列出了出现此异常的两个原因:如果坐标不在边界内,或者如果input int像素数组太小,无法容纳InputHanks,但我刚刚尝试了你的想法,但它仍然存在相同的问题。我尝试了你的想法,但我有相同的问题。我将显示更多代码,因为可能没有错误。但是我尝试了检查每一行,我不明白为什么会发生。
while( count <= array.length ) {
    System.out.println( array[count] );
    ++count;
}