Effect Comparison
original figure
process of color reversal
original figure
process of color reversal
code implementation
-
-
-
import ;
-
import ;
-
import .*;
-
-
public class ImageColor {
-
-
-
/**
-
* @Description: Anti-color
-
* @param imgPath Image path
-
* @param fileUrl Output image path
-
* @throws
-
*/
-
public static void inverse(String imgPath, String fileUrl){
-
try {
-
FileInputStream fileInputStream = new FileInputStream(imgPath);
-
BufferedImage image = (fileInputStream);
-
// Generate character images
-
int w = ();
-
int h = ();
-
BufferedImage imageBuffer = new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB);;
-
// Drawing characters
-
for (int y = 0; y < h; y++) {
-
for (int x = 0; x< w; x++) {
-
int rgb = (x, y);
-
int R = (rgb & 0xff0000) >> 16;
-
int G = (rgb & 0x00ff00) >> 8;
-
int B = rgb & 0x0000ff;
-
int newPixel=colorToRGB(255-R,255-G,255-B);
-
(x,y,newPixel);
-
}
-
}
-
(imageBuffer, "png", new File(fileUrl)); // Output image
-
} catch (Exception e) {
-
();
-
}
-
}
-
-
/**
-
* @Description: Color to rgb values
-
* @throws
-
*/
-
public static int colorToRGB(int red,int green,int blue){
-
int newPixel=0;
-
newPixel=newPixel << 8;
-
newPixel+=red;
-
newPixel=newPixel << 8;
-
newPixel+=green;
-
newPixel=newPixel << 8;
-
newPixel+=blue;
-
return newPixel;
-
-
}
-
-
-
-
public static void main(String[] args) throws IOException {
-
inverse("C:\\Users\\liuya\\Desktop\\","C:\\Users\\liuya\\Desktop\\logo_0.png");
-
}
-
}
single class implementation.Modify the codeand the address of the new image to be generated, just run the main method.
Additional knowledge
The three primary colors in computers are the red, green, and blue of light
0xff0000 forRGBSixteen-digit red
0x00ff00 Green for RGB hexadecimal system
0x0000ff is blue in RGB hexadecimal format
Relevant knowledge
.imageis a standard class library for image processing provided by Java, which contains a set of classes and interfaces for representing, manipulating, and processing image data. This class library provides a wealth of functionality for loading, editing, converting, compositing, and other operations on images.
Here's a detailed breakdown of the
-
Image Representation: Multiple classes are provided to represent image data. One of the most commonly used is the BufferedImage class, which is an Image object with a buffer of image data that allows direct access and modification of the pixel values of an image. Also included are IndexColorModel for representing indexed color models, Raster for representing image data, and ColorSpace for representing color spaces.
-
Image Loading and Saving: Several classes and methods are provided for loading and saving images. For example, the ImageIO class provides static methods to load an image from a file or input stream and save the image to a file or output stream. With ImageIO, developers can easily read and write to various image formats such as JPEG, PNG, GIF, etc.
-
Image Editing and Drawing : Provides classes and methods for image editing and drawing.The Graphics class is an abstract base class that provides basic drawing operations such as drawing lines, filling rectangles, drawing text, and so on. With the Graphics class, you can draw and edit on an image, such as drawing geometric shapes, adding text, drawing images, and so on.
-
Color Model and Adjustment: provides color model related classes and methods for processing color information and adjustment of an image.ColorModel class is an abstract base class representing the color model of an image, which defines operations such as getting and setting pixel values, color space conversion, and so on. With ColorModel, operations such as color space conversion, color adjustment, pixel reading and writing can be performed.
-
Image Filters and Transformations: Provides a number of classes and interfaces for filter and transformation operations. For example, ConvolveOp class can be applied to the convolution matrix to achieve the blurring of the image, sharpening and other effects. AffineTransform class can be used for image translation, rotation, scaling and other geometric transformation operations. These classes and interfaces can be used to perform a variety of filters and transformation operations on the image to achieve special effects processing and transformation of the image.
-
Advanced Image Processing: Provides some advanced image processing functions. For example, the RescaleOp class can be used to adjust the brightness and contrast of an image; the LookupOp class can be used to color map an image through a lookup table; the BandCombineOp class can merge different bands of multiple images. These classes can help developers achieve more complex image processing algorithms and effects.
-
Image encoding and decoding: A number of classes and methods are provided to support image encoding and decoding. For example, ImageWriter and ImageReader are abstract classes that define the basic operations of image encoding and decoding. With these classes, developers can implement custom image encoders and decoders to extend support for different image formats.
-
Image Scaling and Cropping: A number of classes and methods are provided for scaling and cropping images. For example, the AffineTransformOp class can be used to scale, rotate, and translate an image according to a specified affine transform matrix.The CropImageFilter class can be used to crop a specified region of an image. These classes can help developers to achieve image resizing and extraction of localized regions.
To summarize , is a standard class library for image processing provided by Java , which provides a wealth of features for image loading, editing, conversion, compositing and other operations . Developers can use this class library to read, process and save data in a variety of image formats , and apply filters, adjustments , drawing and other operations to achieve more complex image processing needs . Provides developers with a set of powerful and flexible tools , making image processing in Java applications become more convenient and efficient .