I have 1D byte array for the buffered image.I want to convert it to the 2D byte array for that i have written the code as below
File file = new File("/home/tushar/temp.jpg");
try {
input_bf = ImageIO.read(file);
width = input_bf.getWidth();
height = input_bf.getHeight();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
byte [][] image = new byte[width][height];
ByteArrayOutputStream bos = new ByteArrayOutputStream();
try {
ImageIO.write(input_bf, "jpg", bos );
bos.flush();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
byte[] imageInByte = bos.toByteArray();
try {
bos.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
//here is the main logic to convert 1D to 2D
int x=0;
for(int i=0;i<width;i++)
{
for(int j=0;j<height;j++)
{
image[i][j] = imageInByte[x];
x++;
}
}
But i get the exception like
java.lang.ArrayIndexOutOfBoundsException: 26029
at smoothing.main(smoothing.java:70)
The size of 1D array is 26029 which shows the exception.
Now what should i do?
How to convert the 1D to 2D image array?
or can any one know how to convert the image to 2D array?