Image Rotation in Java

Source: Internet
Author: User
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)

.

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.