画像はRGBグレースケールに変換されます。
次に、グレースケール画像が配列に変換され、変換を定義するために実行されます。その結果、配列は「0」と「255」で構成されます。
次に、この配列をBufferedImageに変換する必要があります。
私はコードを使用しました:
public static BufferedImage getImageFromArray(int pixelsMain[][], int width, int height) throws IOException {
int pixels[] = new int[320*240];
for(int i=0, numb=0; i<pixelsMain.length; i++)
for(int j=0; j<pixelsMain[i].length; j++){
pixels[numb]=pixelsMain[i][j];
numb++;
}
BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_BYTE_GRAY);
WritableRaster raster = (WritableRaster) image.getData();
raster.setPixels(0,0,width,height,pixels);
try {
ImageIO.write(image, "bmp", new FileOutputStream("[path]"));
} catch (IOException e) {
e.printStackTrace();
}
return image;
}
ただし、メソッドを実行した後、「255」のすべての値が「-1」に変換されます。
その結果、画像は完全に黒くなります。
問題の解決方法を教えてください。