Image Rotation in Java
Use affinetransform.Getscaleinstance(Double Sx, double Sy ).
An affinetransform instance that executes the rotation operation, and uses it as a parameter to construct
Affinetransformop object, and then call itsFilter(Bufferedimage SRC, bufferedimage DST)
Method,This function is used to rotate bufferedimage.
However, the filter method of affinetransformop returnsBufferedImageAnd
Not necessarilygetBounds2D(BufferedImage)The coordinates of the returned rectangle are the same. If you are sitting in the upper left corner of the rectangle
Marked as negative,That part will not be drawn. Only the non-negative coordinates are drawn in the target bufferedimage.So
DirectBy calling this function for rotation transformation, some parts of the image will be lost. The source image must be placed after rotation
Non-negative, thisSample to obtain the complete image.
The source image can be properly translated before rotation, so that the coordinates of the source image are large enough, and the rotation is not negative.
As shown in 3.2, W and H represent the width and height of the source image respectively.The vertical rectangular ruler that can contain the entire image after rotation
Inch:
Width = H * | sin (theta) | + W * | cos (theta) |.
Height = h * | cos(theta) | +w * | sin(theta) |,
Figure. Image Rotation
In this way, you only need to first translate
[ 1 0 (Width-w)/2 ]
[0 1 (height-h)/2]
[0 0 1]
You can. This can be done through affinetransform. gettranslateinstance (width-Wh)/2, (height-h)/2)
.