Horizontal flipping, zooming, and free-rotation operations for image in Java

Source: Internet
Author: User

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

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.