這篇文章主要為大家詳細(xì)介紹了使用Java如何實(shí)現(xiàn)一個(gè)圖片旋轉(zhuǎn)效果,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,發(fā)現(xiàn)的小伙伴們可以參考一下:
創(chuàng)新互聯(lián)專(zhuān)注于雞西企業(yè)網(wǎng)站建設(shè),成都響應(yīng)式網(wǎng)站建設(shè)公司,成都商城網(wǎng)站開(kāi)發(fā)。雞西網(wǎng)站建設(shè)公司,為雞西等地區(qū)提供建站服務(wù)。全流程按需策劃,專(zhuān)業(yè)設(shè)計(jì),全程項(xiàng)目跟蹤,創(chuàng)新互聯(lián)專(zhuān)業(yè)和態(tài)度為您提供的服務(wù)
Java主要應(yīng)用于:1. web開(kāi)發(fā);2. Android開(kāi)發(fā);3. 客戶(hù)端開(kāi)發(fā);4. 網(wǎng)頁(yè)開(kāi)發(fā);5. 企業(yè)級(jí)應(yīng)用開(kāi)發(fā);6. Java大數(shù)據(jù)開(kāi)發(fā);7.游戲開(kāi)發(fā)等。
具體內(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; } }
以上就是創(chuàng)新互聯(lián)小編為大家收集整理的使用Java如何實(shí)現(xiàn)一個(gè)圖片旋轉(zhuǎn)效果,如何覺(jué)得創(chuàng)新互聯(lián)網(wǎng)站的內(nèi)容還不錯(cuò),歡迎將創(chuàng)新互聯(lián)網(wǎng)站推薦給身邊好友。