由于需求,我把一个灰度图片转成了一个short类型的数组。
File file = new File("grayImage.jpg");
BufferedImage src=ImageIO.read(file);
int width=src.getWidth(null);
int height=src.getHeight(null);
int minX=src.getMinX();
int minY=src.getMinY();
short[] rgb = new short[3];
short[] grayImage=new short[width*height];
for(int i=minX;i<height;i++){
for(int j=minY;j<width;j++){
//System.out.print(bi.getRGB(jw, ih));
int pixel=src.getRGB(j, i);
rgb[0] = (short) ((pixel & 0xff0000 ) >> 16) ;
rgb[1] = (short) ((pixel & 0xff00 ) >> 8) ;
rgb[2] = (short) (pixel & 0xff );
grayImage[i*width+j]=(short)(rgb[0] * 0.299 + rgb[1] * 0.587 + rgb[2] * 0.114);
}
}
现在我对的到的grayImage操作完了,并对像素值做了一些修改,那我应该如何
把short[] grayImage再转成图片格式呢?