java how to convert a int[][] to an BufferedImage -
i have 2d integer array, bufferedimage method "getrgb()". when try convert 2d integer array bufferdimage, black picture.
this method
bufferedimage bufferedimage = new bufferedimage(width, height, bufferedimage.type_int_rgb); (int = 0; < matrix.length; i++) { (int j = 0; j < matrix[0].length; j++) { int pixel=matrix[i][j]; system.out.println("the pixel in matrix: "+pixel); bufferedimage.setrgb(i, j, pixel); system.out.println("the pixel in bufferedimage: "+bufferedimage.getrgb(i, j)); } }
give output:
the pixel in matrix: 0 pixel in bufferedimage: -16777216 pixel in matrix: 721420288 pixel in bufferedimage: -16777216 pixel in matrix: 738197504 pixel in bufferedimage: -16777216 pixel in matrix: 520093696 pixel in bufferedimage: -16777216 pixel in matrix: 503316480 pixel in bufferedimage: -16777216
why every pixel "-16777216"?
thanks!
update
the method returns integer matrix
public int[][] getmatrixofimage(bufferedimage bufferedimage) { int width = bufferedimage.getwidth(null); int height = bufferedimage.getheight(null); int[][] pixels = new int[width][height]; (int = 0; < width; i++) { (int j = 0; j < height; j++) { pixels[i][j] = bufferedimage.getrgb(i, j); } } return pixels; }
all pixels seem black different alpha values. have use type_int_argb not lose alpha channel.
Comments
Post a Comment