简体   繁体   English

在Java中逐像素访问图像

[英]Accessing Image pixel by pixel in Java

Is there any inbuilt java API or class library for accessing pixels in a given image? 是否有用于访问给定图像中像素的内置java API或类库? What I am planning to do is search one image inside another image. 我打算做的是在另一个图像中搜索一个图像。 For example : img1 is 24x24px , img2 is 1024x768px assume that a symbol, similar to img1 may exists in img2 . 例如:img1是24x24px,img2是1024x768px,假设一个符号,类似于img1可能存在于img2中。 Now I want to get X and Y coordinates of the symbol which is similar to the img1. 现在我想获得与img1类似的符号的X和Y坐标。

Yes, there is, if you have your image as a BufferedImage then use the getRGB(int x, int y) method to get the value of the pixel at the position (x, y). 是的,如果您将图像作为BufferedImage则使用getRGB(int x, int y)方法获取位置(x,y)处的像素值。

See the API documentation of java.awt.image.BufferedImage . 请参阅java.awt.image.BufferedImage的API文档。

您可以在Java BufferedImage类中使用getRGB(...)方法。

If you have a java.awt.image.BufferedImage , you can call getRGB() , which returns a array of int s containing the color values of each pixel. 如果你有一个java.awt.image.BufferedImage ,你可以调用getRGB() ,它返回一个int数组,包含每个像素的颜色值。

If you Image is not an instance of BufferedImage , you can use java.awt.image.PixelGrabber to get the same result, using the setPixels() method. 如果Image不是BufferedImage的实例,则可以使用java.awt.image.PixelGrabber使用setPixels()方法获得相同的结果。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM