如何从Java中的R,G,B值获取RGB像素值以获取BufferedImage [英] How to get rgb pixel value from R ,G,B value in java for a BufferedImage

查看:44
本文介绍了如何从Java中的R,G,B值获取RGB像素值以获取BufferedImage的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可以使用以下函数获取r,g,b值.

I can get the r,g,b values using the following functions.

int rgb=bImg.getRGB(i, j);
int r=(rgb>>16) & 0xff; 
int g=(rgb>>8) & 0xff;
int b=(rgb) & 0xff;

现在我对这些值进行一些操作,并希望使用以下函数设置rgb值

Now I do some operations in on those values and want to set the rgb values using the following function

bImg.setRgb(int x,int y,int rgb)

但是我不知道如何从R,G,B值计算出rgb.

But i do not know how to calculate rgb from R,G,B values.

推荐答案

int rgb = (r<<16) + (g<<8) + b;

int rgb = (r<<16)  | (g<<8)  | b;

将执行逆运算,并将 r g b 存储为解码后的单个整数.

will do the inverse operation and store r , g and b into a single integer as you have decoded.

这篇关于如何从Java中的R,G,B值获取RGB像素值以获取BufferedImage的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆