From: http://cping1982.blog.51cto.com/601635/130066/
Original works, allow reprint, please be sure to use hyperlinks in the form of the original source of the article, author information and this statement. Otherwise, the legal liability will be investigated. http://cping1982.blog.51cto.com/601635/130066
Cliché, look directly at the code.
Bufferedimage.getcolormodel (). Gettransparency () to get the original picture transparency is used to generate the cache diagram, in the cache diagram to do the corresponding operation.
/**
* Rotate picture for specified angle
*
* @param bufferedimage
* Target Image
* @param degree
* Angle of rotation
* @return
*/
public static BufferedImage Rotateimage (final bufferedimage BufferedImage,
Final int degree){
int w = bufferedimage.getwidth ();
int h = bufferedimage.getheight ();
int type = Bufferedimage.getcolormodel (). Gettransparency ();
BufferedImage img;
Graphics2D graphics2d;
(graphics2d = (img = new BufferedImage (W, h, type))
. CreateGraphics ()). Setrenderinghint (
Renderinghints.key_interpolation,
Renderinghints.value_interpolation_bilinear);
Graphics2d.rotate (Math.toradians (degree), W/2, H/2);
Graphics2d.drawimage (bufferedimage, 0, 0, NULL);
Graphics2d.dispose ();
return img;
}
/**
* Change image to specified size
*
* @param bufferedimage
* Target Image
* @param W
* Wide
* @param h
* High
* @return
*/
public static BufferedImage Resizeimage (final bufferedimage BufferedImage,
Final int W, final int h){
int type = Bufferedimage.getcolormodel (). Gettransparency ();
BufferedImage img;
Graphics2D graphics2d;
(graphics2d = (img = createimage (w, h, type))
. CreateGraphics ()). Setrenderinghint (
Renderinghints.key_interpolation,
Renderinghints.value_interpolation_bilinear);
Graphics2d.drawimage (bufferedimage, 0, 0, W, h, 0, 0, BufferedImage
. GetWidth (), bufferedimage.getheight (), NULL);
Graphics2d.dispose ();
return img;
}
/**
* Flip Image horizontally
*
* @param bufferedimage Target image
* @return
*/
public static BufferedImage Flipimage (final bufferedimage bufferedimage){
int w = bufferedimage.getwidth ();
int h = bufferedimage.getheight ();
BufferedImage img;
Graphics2D graphics2d;
(graphics2d = (img = createimage (w, H, bufferedimage
. Getcolormodel (). Gettransparency ())). CreateGraphics ())
. DrawImage (bufferedimage, 0, 0, W, H, W, 0, 0, h, NULL);
Graphics2d.dispose ();
return img;
}
This article is from the "Java How to play" blog, please be sure to keep this source http://cping1982.blog.51cto.com/601635/130066
(RPM) Horizontal flipping, zooming, and free rotation of image in Java