Resize image while rotating image in android

前端 未结 3 561
滥情空心
滥情空心 2021-01-16 19:38

I\'m working with android project in which I want to rotate image along with touch to some fix pivot point. I have completed all these things but I am facing one problem: Wh

3条回答
  •  误落风尘
    2021-01-16 20:05

    The problem has to do with applying your Bitmap to the ImageView. Create a BitmapDrawable first, then apply. There are some scaling problems that occur if you don't. I'm not sure why, maybe someone else could provide insight. I ran into the same problem when creating a compass app and came to this thread on a search, so I thought I would update with the fix that worked.

    int rotation = (int) Math.toDegrees(r);
    Matrix matrix = new Matrix();
    matrix.postRotate(rotation);
    
    source = Bitmap.createBitmap(currentBitmap, 0, 0, currentBitmap.getWidth(), currentBitmap.getHeight(), matrix, false);
    *BitmapDrawable newBmd = new BitmapDrawable(source);
    
    imageView.setImageDrawable(newBmd);*
    imageView.setScaleType(ScaleType.CENTER);
    

提交回复
热议问题