In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly introduces java how to get the RGB value of the image where the mouse is located, the content is detailed and easy to understand, the operation is simple and fast, and it has a certain reference value. I believe you will gain something after reading this java article on how to get the RGB value of the image where the mouse is located. Let's take a look.
Import Java.awt.*
Import java.awt.event.*
Import java.awt.image.*
Import javax.swing.*
Public class GetRectPixel {
Public GetRectPixel () {
ImageHolder holder = new ImageHolder ()
JFrame frame = new JFrame ()
JPanel panel = new JPanel ()
Panel.add (holder)
Frame.getContentPane () add (panel)
Frame.setSize (400400)
Frame.setVisible (true)
}
Public static void main (String [] args) {
GetPixel getpixel = new GetPixel ()
}
}
Class ImageHolder extends Canvas {
BufferedImage bi; / / create a buffer image
Image image
MediaTracker mt; / / create a media tracker
Int imageWidth; / / Image width
Int imageHeight;// image height
Public ImageHolder () {
Mt = new MediaTracker (this)
Try {
Image = Toolkit.getDefaultToolkit () .createImage ("gigi3.jpg")
Mt.addImage (image,0)
Mt.waitForAll (); / / wait until all the images are finished loading
ImageWidth = image.getWidth (this); / / get the width of the single front image
ImageHeight = image.getHeight (this); / / get the length of the current image
}
Catch (Exception e) {}
Bi = new BufferedImage (imageWidth,imageHeight,BufferedImage.TYPE_INT_RGB)
AddMouseListener (new MouseAdapter () {
Public void mouseClicked (MouseEvent me) {
/ / get the horizontal and vertical coordinates of the current position of the mouse
Int mouseX = (int) me.getPoint () .getX ()
Int mouseY = (int) me.getPoint () .getY ()
/ / get the RGB value there
GetPixel (mouseX,mouseY)
}
});
SetSize (imageWidth,imageHeight)
}
Public void paint (Graphics g) {
Int xCenter = (getSize () .width / 2)-(imageWidth / 2)
Int yCenter = (getSize () .height / 2)-(imageHeight / 2)
G.drawImage (image, xCenter, yCenter, imageWidth, imageHeight, this)
}
Public void getPixel (int x pencil int y) {
/ / get the color model of ImageHolder
ColorModel cm = this.getColorModel ()
/ / returns the pixel color component (ImageHolder) in the form of rgb.
Int rgb = cm.getRGB (xroomy)
/ / the values of rmag and b were obtained respectively.
Int red = (rgb > > 16) & 0xff
Int green = (rgb > > 8) & 0xff
Int blue = (rgb) & 0xff
System.out.println ("(" + red+ "," + green+ "," + blue+ "))
}
}
This is the end of the article on "how to get the RGB value of the image where the mouse is located by java". Thank you for reading! I believe you all have a certain understanding of the knowledge of "how to get the rgb value of the image where the mouse is located". If you want to learn more, you are welcome to follow the industry information channel.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.