In this section of Java graphic tutorial, you are going to study about the how to give different color effects like Brightness, Contrast to your Image.
We are providing you an example, where an image shows different color effects. We have used the radio buttons for choosing color effects like Brightness, Contrast Increase, Contrast Decrease, Darkness, Negative, ChangeColor and Reset. The ActionListener class is used to call those effects on the image.
Following code gets the default ToolKit and returns an image which gets pixel data from the specified file:
The MediaTracker class provides a number of media objects including images. Create an object of MediaTracker and call its addImage() method for the image to be tracked. The method waitForAll() starts loading image tracked by the media tracker.
LookUpTable class contains data arrays for one or more components of an image. ShortLookupTable is a subclass of LookUpTable , which contains short data. To implements a lookup operation from the source to the destination, we have used the class LookUpOp. The ColorSpace class represents a color space resource for a color. The ColorConvertOp class performs a pixel-to-pixel color conversion of the data in the source image. The ColorSpace.getInstance(ColorSpace.CS.Gray) method returns a ColorSpace representing one of the specific predefined color spaces. The colorConvert.filter() method converts the color of source BufferedImage. The method lop.filter(image, image) perform lookup operation on buffered image.
Here is the code of ImageColorEffect.java
Output will be displayed as:
On clicking to the 'Darkness' radio button, darkness will increase.
Liked it! Share this Tutorial