开发者

How to make a color picker from image?

开发者 https://www.devze.com 2023-01-01 11:01 出处:网络
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.

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

精彩评论

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