Java實現(xiàn)圖片旋轉(zhuǎn)、指定圖像大小和水平翻轉(zhuǎn)
更新時間:2019年02月10日 08:43:55 作者:benw1988
這篇文章主要為大家詳細介紹了Java實現(xiàn)圖像旋轉(zhuǎn),指定圖像大小,水平翻轉(zhuǎn)圖像,具有一定的參考價值,感興趣的小伙伴們可以參考一下
本文實例為大家分享了Java實現(xiàn)圖片旋轉(zhuǎn)、指定圖像大小、水平翻轉(zhuǎn),供大家參考,具體內(nèi)容如下
package com.zeph.j2se.image; import java.awt.Graphics2D; import java.awt.RenderingHints; import java.awt.image.BufferedImage; public class ImageOperate { /** * 旋轉(zhuǎn)圖片為指定角度 * * @param bufferedimage * 目標(biāo)圖像 * @param degree * 旋轉(zhuǎn)角度 * @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; } /** * 變更圖像為指定大小 * * @param bufferedimage * 目標(biāo)圖像 * @param w * 寬 * @param h * 高 * @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 = new BufferedImage(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; } /** * 水平翻轉(zhuǎn)圖像 * * @param bufferedimage * 目標(biāo)圖像 * @return */ public static BufferedImage flipImage(final BufferedImage bufferedimage) { int w = bufferedimage.getWidth(); int h = bufferedimage.getHeight(); BufferedImage img; Graphics2D graphics2d; (graphics2d = (img = new BufferedImage(w, h, bufferedimage .getColorModel().getTransparency())).createGraphics()) .drawImage(bufferedimage, 0, 0, w, h, w, 0, 0, h, null); graphics2d.dispose(); return img; } }
以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
Java使用Fastjson進行JSON數(shù)據(jù)操作教程詳解
Fastjson?是一個?Java?庫,可以用來將?Java?對象轉(zhuǎn)換為它們的?JSON?表示,本文主要為大家詳細介紹了Java如何使用Fastjson進行JSON數(shù)據(jù)操作,需要的可以參考下2023-12-12Spring MVC 404 Not Found無錯誤日志的解決方法
這篇文章主要為大家詳細介紹了Spring MVC 404 Not Found無錯誤日志的解決方法,具有一定的參考價值,感興趣的小伙伴們可以參考一下2017-12-12Thymeleaf 3.0 自定義標(biāo)簽方言屬性的實例講解
這篇文章主要介紹了Thymeleaf 3.0 自定義標(biāo)簽方言屬性的實例講解,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2020-09-09