2015-08-15 100 views
0

谁能告诉我如何在Android中一次又一次旋转90度的图像?我做了一个按钮,我用它来将图像旋转90度。该代码只适用于一次旋转,在第二次旋转时,应用程序崩溃。任何人都可以帮助我吗?假设我从相机的图库中获取图像,并且'图像'中的位图变量为'变量','imgPicture'为图像视图。这是我的代码。在Android中一次又一次旋转图像90度

public void Rotate(View view) 
    { 




    Matrix m = new Matrix(); 
     m.postRotate(90); 

     image = Bitmap.createBitmap(image, 0, 0, width_temp1, height_temp1, m, true); 
     imgPicture.setImageBitmap(image); 

     // width_temp1 and height_temp1 are the width and height of the image that i'm getting 
     // using the .getWidth() and .getHeight() functions of the bitmap. 




} 

回答

0

您不能为每次旋转创建一个位图。视图有一个属性“RotationX”,您可以调用setRotationX来实现旋转。

+0

这一切都很好,但这里是问题,我从画廊加载的一些图片旋转,一些出来罚款,通常是我从相机拍摄得到的旋转方式错误。你可以说,我可以使用旋转一次,并完成它,但如果用户想再次旋转它呢?那我该怎么办?因为应用程序第二次崩溃,因为你刚才告诉我的原因,我点击了按钮。 –

+0

实际上没关系,我想通了。我找到使用exif的方向,然后旋转图像,如果方向是90.谢谢你的帮助,虽然:) –