* 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源代码的信息别忘了在本站进行查找喔 。
推荐阅读
- 直播伴侣天气插件,正规英文名
- 如何转型新自媒体营销策划,如何转型新自媒体营销策划方案
- 专业开发游戏赚钱,开发游戏的人怎么挣钱
- 什么是模拟体育赛事游戏,体育模拟考试是什么意思
- php和数据库怎么连接 php和数据库怎么连接使用
- 神魔养殖场txt下载的简单介绍
- 品牌商如何利用直播电商,怎样使用直播带品牌的方式推广
- thinkphp排除条件,thinkphp5多条件查询
- mysql本地端口怎么改 mysql怎么改端口号