2015-08-15 70 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.謝謝你的幫助,雖然:) –