Resize image while rotating image in android

前端 未结 3 523
滥情空心
滥情空心 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 19:55

    You don't rotate the image, you rotate the canvas. Scaling is done using setBounds(). See this question for a bit of help.

    0 讨论(0)
  • 2021-01-16 20:03

    You're rotating a rectangular bitmap. When you do so, the canvas size has to change in order to accommodate the full image. You would need to manually crop after the rotate to get the function you desire.

    0 讨论(0)
  • 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);
    
    0 讨论(0)
提交回复
热议问题