开发者

How to make a color picker from image?

How can I make a color picker, which gets a value of images pi开发者_如何转开发xel and refreshes any time I click on different pixel, shows it? It must be done in java.


Load the image in a frame.
Use the mouse coordinates from the upper left corner of the image.

Assuming your image is loaded into BufferedImage, you can use:

int x,y; //populated from Mouse coordinates
int rgb = myBufferedImage.getPixel(x,y);

//to extract colors    
int red = (rgb & 0x00ff0000) >> 16;
int green = (rgb & 0x0000ff00) >> 8;
int blue = rgb & 0x000000ff;

// and to create a new Java color
Color c = new Color(red,blue,green); 
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜