您的位置:首页 > 编程语言 > Java开发

使用 Java 进行图像处理 - 取得图像上指定位置像素的 rgb 颜色分量

2016-05-18 09:08 876 查看
版权声明:转载时请务必保留以下作者信息和链接

作者:陈维(chenweionline@hotmail.com)作者的网站:http://www.chenwei.mobi


/**


* 取得图像上指定位置像素的 rgb 颜色分量。


* @param image 源图像。


* @param x 图像上指定像素位置的 x 坐标。


* @param y 图像上指定像素位置的 y 坐标。


* @return 返回包含 rgb 颜色分量值的数组。元素 index 由小到大分别对应 r,g,b。


*/


public static int[] getRGB(BufferedImage image, int x, int y){


int[] rgb = new int [3];


int pixel = image.getRGB(x, y);


rgb[0] = (pixel & 0xff0000) >> 16;


rgb[1] = (pixel & 0xff00) >> 8;


rgb[2] = (pixel & 0xff);




return rgb;


}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: