Knowledge Point: The AffineTransform class represents 2D affine transformations. It performs linear ing from 2D coordinates to other 2D coordinates, retaining the line's "Linearity" and "parallelism ". You can use a series of translation, scale, flip, rotation, and shear to construct the affine transformation.
AffineTransformOp uses AffineTransformOp to perform linear ing from 2D coordinates in the source image or Raster to 2D coordinates in the target image or Raster.
BufferedImage
Filter (BufferedImage src, BufferedImage dst)
Convert the source BufferedImage and store the result in the target BufferedImage.
1. Application 1:
Public void test01 (){
Try {
File fi = new File ("D:/1.jpg"); // large image File
File fo = new File ("D:/2.jpg"); // The small image File to be converted
// Create an AffineTransform object
AffineTransform transform = new AffineTransform ();
// Obtain the BufferedImage object from the large image file.
BufferedImage bis = ImageIO. read (fi );
Int w = bis. getWidth ();
Int h = bis. getHeight ();
// Double scale = (double) w/h;
// Modify the mw value and the zoom size
Int scaling = 120;
Int nw = scale;
Int nh = (nw * h)/w;
If (nh> scale ){
Nh = scale;
Nw = (nh * w)/h;
}
Double sx = (double) nw/w;
Double sy = (double) nh/h;
// Implement scaling. sx scales down the X axis. sy scales down the Y axis.
Transform. setToScale (sx, sy );
AffineTransformOp ato = new AffineTransformOp (transform, null );
// Recreate a BufferedImage object
BufferedImage bid = new BufferedImage (nw, nh, BufferedImage. TYPE_3BYTE_BGR );
// Execute the conversion
Ato. filter (bis, bid );
// Save the image
ImageIO. write (bid, "jpeg", fo );
} Catch (Exception e ){
E. printStackTrace ();
}
}