像素点运算java源代码 像素点运算java源代码是什么( 四 )


* the file (usually 8bit RGB put into an 64bit double)
*
* @return The data of the image.
*/
public int[][] getImageRGB() {
return imageRGB;
}
/**
* Write to codefn/code file the codedata/code using the
* codewidth, height/code variables. Data is assumed to be 8bit RGB.
*
* @throws FileNotFoundException
*if the directory/image specified is wrong
* @throws IOException
*if there are problems reading the file.
*/
public static void writeImage(String fn, int[] data, int width, int height)
throws FileNotFoundException, IOException {
FileOutputStream fOut = new FileOutputStream(fn);
JPEGImageEncoder jpeg_encode = JPEGCodec.createJPEGEncoder(fOut);
BufferedImage image = new BufferedImage(width, height,
BufferedImage.TYPE_INT_RGB);
image.setRGB(0, 0, width, height, data, 0, width);
jpeg_encode.encode(image);
fOut.close();
}
/**
* Read the image from the specified file.
*
* @throws FileNotFoundException
*pretty obvious
* @throws IOException
*filesystem related problems
*/
private void readImage() throws FileNotFoundException, IOException {
FileInputStream fIn = new FileInputStream(filename);
JPEGImageDecoder jpeg_decode = JPEGCodec.createJPEGDecoder(fIn);
BufferedImage image = jpeg_decode.decodeAsBufferedImage();
width = image.getWidth();
height = image.getHeight();
int[] rgbdata = https://www.04ip.com/post/new int[width * height];
image.getRGB(0, 0, width, height, rgbdata, 0, width);
ints = rgbdata;
bytes = new byte[rgbdata.length];
doubles = new double[rgbdata.length];
imageRGB = new int[3][rgbdata.length];
for (int i = 0; ibytes.length; i++) {
bytes[i] = (byte) (rgbdata[i]0xFF);
doubles[i] = (double) (rgbdata[i]);
imageRGB[0][i] = (rgbdata[i]16711680)16;
imageRGB[1][i] = (rgbdata[i]65280)8;
imageRGB[2][i] = (rgbdata[i]255);
}
}
}
上述代码可以复制,粘贴使用,有方法的注视,getImageRGB() 就可以获得所有像素的RGB值,你就可以在其他方法里处理这个二维数组 , 得到你想要的平均值了 , 处理后的值,记得把值逆运算,再转换到Int[]里,就可以用,writeImage()输出图像了 。
像素点运算java源代码的介绍就聊到这里吧,感谢你花时间阅读本站内容,更多关于像素点运算java源代码是什么、像素点运算java源代码的信息别忘了在本站进行查找喔 。

推荐阅读