亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

Java:旋轉圖像

Java:旋轉圖像

aluckdog 2019-11-04 09:30:59
我需要能夠單獨旋轉圖像(在Java中)。到目前為止,我發現的唯一東西是g2d.drawImage(image,affinetransform,ImageObserver)。不幸的是,我需要在特定點繪制圖像,并且沒有一種方法帶有參數1.分別旋轉圖像和2.允許我設置x和y。任何幫助表示贊賞
查看完整描述

3 回答

?
萬千封印

TA貢獻1891條經驗 獲得超3個贊

這就是您可以做到的。這段代碼假設存在一個名為“ image”的緩沖圖像(如您的評論所說)


// The required drawing location

int drawLocationX = 300;

int drawLocationY = 300;


// Rotation information


double rotationRequired = Math.toRadians (45);

double locationX = image.getWidth() / 2;

double locationY = image.getHeight() / 2;

AffineTransform tx = AffineTransform.getRotateInstance(rotationRequired, locationX, locationY);

AffineTransformOp op = new AffineTransformOp(tx, AffineTransformOp.TYPE_BILINEAR);


// Drawing the rotated image at the required drawing locations

g2d.drawImage(op.filter(image, null), drawLocationX, drawLocationY, null);


查看完整回答
反對 回復 2019-11-04
?
米琪卡哇伊

TA貢獻1998條經驗 獲得超6個贊

一種簡單的方法,而無需使用如此復雜的draw語句:


    //Make a backup so that we can reset our graphics object after using it.

    AffineTransform backup = g2d.getTransform();

    //rx is the x coordinate for rotation, ry is the y coordinate for rotation, and angle

    //is the angle to rotate the image. If you want to rotate around the center of an image,

    //use the image's center x and y coordinates for rx and ry.

    AffineTransform a = AffineTransform.getRotateInstance(angle, rx, ry);

    //Set our Graphics2D object to the transform

    g2d.setTransform(a);

    //Draw our image like normal

    g2d.drawImage(image, x, y, null);

    //Reset our graphics object so we can draw with it again.

    g2d.setTransform(backup);


查看完整回答
反對 回復 2019-11-04
  • 3 回答
  • 0 關注
  • 425 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號