2
我有一個包含512x512灰度圖像的像素值的1維數組像素。我想寫入一個PNG文件。我寫了下面的代碼,但它只是創建一個空白圖像。從1d陣列構建圖像
public void write(int width ,int height, int[] pixel) {
try {
// retrieve image
BufferedImage writeImage = new BufferedImage(512,512,BufferedImage.TYPE_BYTE_GRAY);
File outputfile = new File("saved.png");
WritableRaster raster = (WritableRaster) writeImage.getData();
raster.setPixels(0,0,width,height,pixel);
ImageIO.write(writeImage, "png", outputfile);
} catch (IOException e) {
}
爲什麼近距離投票?它顯示了努力並且清楚地表明瞭它,這似乎是一個模範問題。 – 2013-03-05 21:20:06