我正在尝试对彩色图像进行一些图像处理,为此我需要分离 RGB 值并分别修改它们。我只是在增加亮度滤镜。我在java中这样做。有人可以帮我吗
1 回答
You have a few options.
First, you need to be able to load an image that supports the BufferedImage
class. For this, you're best using the ImageIO
API. Take a look at Reading/Loading an Image.
Once you have this, you can obtain the pixel information in a verity of ways.
One of the simplest is to use BufferedImage#getRGB
, which returns a packed integer of the pixel.
Depending on the type of image, you can obtain the individual color values Color(int, boolean)
, which will unpack the integer accordingly (you can also do this manually, but I never remember the maths and this is simpler).
Alternativly, you can access the Raster
directly, via BufferedImage#getData
, which provides you access to more methods for manipulating the underlying pixel information (such as grabbing regions of pixels for example)
Now, if all that sounds like more fun then you can handle, you can easily perform image brightening using a BufferedImageOp
...
See, Adjust brightness and contrast of BufferedImage in Java and How to change the contrast and brightness of an image stored as pixel values and Change brightness of image using RescaleOp for examples (these where just the top few that popped up on Google)