我正在苦于位图旋转。我希望围绕一个替代轴旋转一个图形,但无论我做什么,我都只能让它围绕中心点旋转,放入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