问题描述
我有一个ImageView的,我基本上是试图使一个温度计式的仪表。我已经添加了下面的测试图像,我基本上是试图旋转图像。第一图像具有在其标准布局的图像。在尝试旋转图像,宽度仍然充满屏幕,但它缩放图像向下腾出空间角落,使得实际的图像显得更小。我想要的图像,以保持完全相同的大小,但旋转基于传递给它的矩阵。
I have an imageView and I am basically trying to make a thermometer style gauge. I have added an image below for testing and I am basically trying to rotate the image. The first picture has the image in its standard layout. After trying to rotate the image, The width still fills the screen, but it scales the image down to make room for the corners, making the actual image appear smaller. I want the image to remain the exact same size, but rotate based on the Matrix passed to it.
下面是code我使用了轮换:
Here is the code I am using for the rotation:
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
circle = (ImageView) findViewById(R.id.imageView1);
Bitmap myImg = BitmapFactory.decodeResource(getResources(), R.drawable.rotated);
Matrix matrix = new Matrix();
matrix.postRotate(45);
Bitmap rot = Bitmap.createBitmap(myImg, 0, 0, myImg.getWidth(), myImg.getHeight(),
matrix, true);
circle.setImageBitmap(rot);
}
所以,我基本上需要红/绿圈边缘到达屏幕的边缘。这可能与ImageView的或者我需要写一个自定义视图,让东西在屏幕之外?顺便说一句,我不是真正会得出这样的整圈,这仅仅是一个例子了解我的问题。
So, I basically need the red/green circle edge to reach the edge of the screen. Is this possible with an imageView or will I need to write a custom view to allow stuff to be off screen? By the way, I am not actually gonna draw this whole circle, this is just an example to get my issue across.
推荐答案
您必须计算实际的新的宽度和高度。尝试使用一些三角
You have to calculate the actual new width and height.try using some trigonometry
newHeight =身高/罪(阿尔法)
,其中alpha是你的旋转角度......
newHeight = height/sin(alpha)
, where alpha is your rotation angle...
newWidth = width/cos(alpha)
然后:
Bitmap rot = Bitmap.createBitmap(myImg, 0, 0, newWidth, newHeight ,
matrix, true);
不知道有关的计算,我没有检查,但我认为它正确的,无论如何,这是一个很大的提示;)
not sure about the calculation, I didn't check it, but I think it correct, anyway, it's a great hint ;)
这篇关于安卓:ImageView的旋转缩放的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!