欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

Java圖像之自定義角度旋轉(zhuǎn)(實(shí)例)

 更新時(shí)間:2017年09月05日 09:40:33   作者:雪落殘痕  
這篇文章主要介紹了Java圖像之自定義角度旋轉(zhuǎn)(實(shí)例),需要的朋友可以參考下

        圖像的旋轉(zhuǎn)需要調(diào)用 Graphics2D 類的rotate()方法,該方法將根據(jù)指定的弧度旋轉(zhuǎn)圖像。

語法如下:

rotate(double theta)

        其中, theta 是指旋轉(zhuǎn)的弧度。

說明:該方法只接受旋轉(zhuǎn)的弧度作為參數(shù),可以使用 Math 類的 toRadians()方法將角度轉(zhuǎn)換為弧度。 toRadians()方法接受角度值作為參數(shù),返回值是轉(zhuǎn)換完畢的弧度值。

實(shí)例代碼:

/** *//**
 * 旋轉(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);// 旋轉(zhuǎn),degree是整型,度數(shù),比如垂直90度。
 graphics2d.drawImage(bufferedimage, 0, 0, null);// 從bufferedimagecopy圖片至img,0,0是img的坐標(biāo)。
 graphics2d.dispose();
 return img;// 返回復(fù)制好的圖片,原圖片依然沒有變,沒有旋轉(zhuǎn),下次還可以使用。
 }

 /** *//**
 * 變更圖像為指定大小
 * 
 * @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;// 空?qǐng)D片。
 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;
 }

 /** *//**
 * 水平翻轉(zhuǎn)圖像
 * 
 * @param bufferedimage 目標(biāo)圖像
 * @return
 */
 public static BufferedImage flipImage(final BufferedImage bufferedimage){
 int w = bufferedimage.getWidth();// 得到寬度。
 int h = bufferedimage.getHeight();// 得到高度。
 BufferedImage img;// 空?qǐng)D片。
 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;
 } 

總結(jié)

        以上就是本文的全部?jī)?nèi)容,希望對(duì)大家有所幫助,如果大家有任何疑問請(qǐng)給我留言,小編會(huì)及時(shí)回復(fù)大家的。在此也非常感謝大家對(duì)腳本之家網(wǎng)站的支持!

相關(guān)文章

最新評(píng)論