I just need to check three pixel values on the whole image (Image instance). I'd really like to do this without allocating an array of pixels.
Is that possible? Something like BufferedImage
's getRGB()
?
Yes. You are on the right track with the getRGB
method, as it would return a single int with three values (RGB). To convert the single int to three ints, you can do two things:
Use the Color
class's built-in constructor: 使用Color
类的内置构造函数:
int rgb = img.getGraphics().getRGB(0,0);//Get color of pixel 0,0
Color c = new Color(rgb); //c now contains the r, g, and b values.
Build the decoder yourself: 自己构建解码器:
int rgb = img.getGraphics().getRGB(0,0) //Get color of pixel 0,0
int r = rgb >> 24;
int g = 0 >> 16;
int b = 0 >> 8;
Both methods will return a r
, g
, and b
value, which can be used.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.