开发者

Rotated image in ImageView

I want to show an arrow that indicates the direction towards a goal, using the orien开发者_如何学编程tation sensor and current GPS position. Everything works well, except that I want to rotate the arrow image in my ImageView.

The current code, which shows the arrow pointing upwards, is this:

ImageViewArrow.setImageResource(R.drawable.arrow);

What is the best solution for showing the arrow, rotated by N degrees?

I tried this, but it gave messed up graphics:

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);


here you can find a tutorial

http://www.anddev.org/resize_and_rotate_image_-_example-t621.html


There is a matrix parameter in the createBitmap method that can be used for resizing and rotating the image. You could try something like the following:

    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); ` 
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜