I've got a two-dimensional array of doubles which is filtered values of an image. I want to convert this array back to a BufferedImage
. How is it possible to cast an double[][]
to a BufferedImage
?
BufferedImage b = new BufferedImage(arr.length, arr[0].length, 3);
Graphics c = b.getGraphics();
PrintWriter writer = new PrintWriter("the-file-name.txt", "UTF-8");
for(int i=0; i< arr.length; i++){
for (int j=0; j<arr[0].length; j++){
c.drawString(String.valueOf(arr[i][j]), i, j);
writer.print(arr[i][j]+" ");
}
writer.println();
}
ImageIO.write(b, "jpg", new File("CustomImage.jpg"));
System.out.println("end");
When I am plot the file-name.txt in matlab with imshow I can see my filtered image. However the CustomImage.jpg contains just one color. Any idea why?
THe result with c.drawString(String.valueOf(arr[i][j]), i, j):
c.drawString(String.valueOf(arr[i][j]), 0+(i*10), 0+(j*10)):
Matlab plor the double of arr first the double of arrays and second the initial gray scaled image:
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…