ImageView中的旋转图像

时间:2010-05-09 15:18:27

标签: java android

我想使用方向传感器和当前GPS位置显示一个箭头,指示朝向目标的方向。一切都很好,除了我想在ImageView中旋转箭头图像。

显示向上箭头的当前代码是:

ImageViewArrow.setImageResource(R.drawable.arrow);

显示旋转N度的箭头的最佳解决方案是什么?

我尝试了这个,但它给了搞乱的图形:

Matrix matrix = new Matrix(); 
matrix.postRotate(Rotation);
Bitmap bitmapOrg = BitmapFactory.decodeResource(getResources(), 
  R.drawable.arrow); 
Bitmap resizedBitmap = Bitmap.createBitmap(bitmapOrg, 0, 0,
  bitmapOrg.getWidth(),bitmapOrg.getHeight(), matrix, true); 
BitmapDrawable bmd = new BitmapDrawable(resizedBitmap);
InfoArrow.setScaleType(ScaleType.CENTER);
InfoArrow.setImageDrawable(bmd);

2 个答案:

答案 0 :(得分:1)

答案 1 :(得分:0)

createBitmap方法中有一个矩阵参数,可用于调整图像大小和旋转图像。您可以尝试以下内容:

    Matrix matrix = new Matrix(); 
    // to rotate the image bitmap use post Rotate
    matrix.postRotate(45); 


    Bitmap rotatedImage = Bitmap.createBitmap(bitmapOrg, 0, 0, 
                      width, height, matrix, true); ` 
相关问题