When zooming and capturing images, you will find that the processing of PNG images with transparent effects will have unexpected effects, and many black lines are inexplicably amazing. Because there is no transparent effect in many image formats, errors may occur during parsing.
The alpha channel refers to the transparency and translucent aspect of an image. For example, a 16-Bit Bitmap may represent red in five bits for each pixel in the image, 5 green, 5 blue, and the last element is Alpha. In this case, it either indicates transparency or not. If a 32-Bit Bitmap is used for storage, 8 bits are used for red, green, and blue respectively, and the remaining 8 bits are used to indicate different levels of transparency.
During Processing, if the following code is used to cut a general image:
Image image = bi.getScaledInstance(srcW, srcH, Image.SCALE_DEFAULT);
cropFilter = new CropImageFilter(x, y, width, height);
img = Toolkit.getDefaultToolkit().createImage(
new FilteredImageSource(image.getSource(), cropFilter));
BufferedImage tag = new BufferedImage(width, height,
BufferedImage.TYPE_INT_RGB);
Graphics2D g = (Graphics2D) tag.getGraphics();
g.setRenderingHint(RenderingHints.KEY_INTERPOLATION,
RenderingHints.VALUE_INTERPOLATION_BILINEAR);
g.drawImage(img, 0, 0, null);
g.dispose();
ImageIO.write(tag, "jpg", new File(imageFullPath));
The problem lies inRenderinghints. key_interpolationAs shown in the preceding figure, this operation does not contain the alpha channel.Bufferedimage. type_int_argb_preAnd then return to normal. The meanings of each value in bufferedimage are as follows (copy from others' blog ):
Bufferedimage. type_int_rgb: 8-bit RGB color component without alpha channel.
Bufferedimage. type_int_argb: 8-bit rgba color component with alpha channel.
Bufferedimage. type_int_argb_pre: 8-bit rgba color component, pre-multiplied by Alpha.
Bufferedimage. type_int_bgr: 8-bit RGB color components for Windows or Solaris images without Alpha channels.
Bufferedimage. type_3byte_bgr: Eight-bit GBA color component. Three colors, blue, green, and red, are stored in three bytes without Alpha.
Bufferedimage. type_4byte_abgr: 8-bit rgba color component. Three colors, blue, green, and red, and one-byte Alpha, are stored in three bytes.
Bufferedimage. type_4byte_abgr_pre: it has three colors, blue, green, and red, and 1-byte Alpha, which are stored in 3 bytes.
Bufferedimage. type_ushort_565_rgb: an image with 5-6-5rgb color components (5-bit red, 6-Bit green, and 5-bit blue) without Alpha.
Bufferedimage. type_ushort_555_rgb: Images with 5-5rgb color components (5-bit red, 5-Bit green, and 5-bit blue) without Alpha.
Bufferedimage. type_byte_gray: indicates an unsigned byte grayscale image (no index ).
Bufferedimage. type_ushort_gray: indicates an unsigned short grayscale image (unindexed ).
Bufferedimage. type_byte_binary: indicates an opaque 1, 2, or 4-bit image packaged in bytes.
Bufferedimage. type_byte_indexed: indicates the byte image with an index.