【发布时间】:2013-02-20 10:43:48
【问题描述】:
我有一个一维数组像素,其中包含 512x512 灰度图像的像素值。我想把它写成一个png文件。我编写了以下代码,但它只是创建了一个空白图像。
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) {
}
【问题讨论】:
-
为什么是近距离投票?它显示了努力并明确说明,这似乎是一个模范问题。
标签: java image image-processing bufferedimage grayscale