我正在苦於位圖旋轉。我希望圍繞一個替代軸旋轉一個圖形,但無論我做什麼,我都只能讓它圍繞中心點旋轉,放入postTranlate。 preTranslate,以任何順序設置翻譯不起作用我也嘗試了postRotate(45,0,0),但它總是圍繞中心旋轉。 下面的代碼採取互聯網我會做什麼來改變它的旋轉點,下面的代碼使用的是正方形的發射器圖標,我正在使用像箭頭一樣的細長圖形。圍繞替代軸旋轉
// Rotate image to 45 degrees.
public void RotateImage(){
ImageView image;
Bitmap bMap;
Matrix matrix;
//Get ImageView from layout xml file
image = (ImageView) findViewById(R.id.imageView1);
//Decode Image using Bitmap factory.
bMap = BitmapFactory.decodeResource(getResources(), R.drawable.ic_launcher);
//Create object of new Matrix.
matrix = new Matrix();
//set image rotation value to 45 degrees in matrix.
matrix.postRotate(45);
//Create bitmap with new values.
Bitmap bMapRotate = Bitmap.createBitmap(bMap, 0, 0,
bMap.getWidth(), bMap.getHeight(), matrix, true);
//put rotated image in ImageView.
image.setImageBitmap(bMapRotate);
}
我曾嘗試下面的代碼,但它仍然繞中心旋轉,或者至少出現過
public void RotateImage{
ImageView image;
Bitmap bMap;
Matrix matrix;
//Get ImageView from layout xml file
image = (ImageView) findViewById(R.id.imageView);
//Decode Image using Bitmap factory.
bMap = BitmapFactory.decodeResource(getResources(), R.drawable.ic_launcher);
//Create object of new Matrix.
matrix = new Matrix();
//set image rotation value to 45 degrees in matrix.
matrix.setTranslate(-100,-200);
matrix.postRotate(angle);
matrix.postTranslate(100,200);
//Create bitmap with new values.
Bitmap bMapRotate = Bitmap.createBitmap(bMap, 0, 0,
bMap.getWidth(), bMap.getHeight(), matrix, true);
//put rotated image in ImageView.
image.setImageBitmap(bMapRotate);
感謝
矩陣不會出現有一個旋轉的方法我猜你可能意味着postRotate (45,a,b)仍然看起來圍繞中心旋轉,文檔確實表明這可以工作,但是我總是出現在中間我猜這個視圖可能會重新調整它,但不能解決它。 – user3129787 2014-08-31 08:36:59
@ user3129787你能提供你正在使用的示例值嗎?同時發佈a和b各種值的輸出屏幕截圖。 – 2014-08-31 08:55:56