2013-04-01 99 views
0

我正在做一個程序,我們正在使用相機拍攝照片並將其存儲在私人文件夾中。從中獲取圖像並將其顯示在網格視圖中。單擊網格視圖時顯示全屏圖像。 我面臨的問題是當相機處於肖像模式時,圖像質量是完美的。但是如果相機處於橫向模式,它會顯示拉伸的圖像我如何克服這一點。麻煩在顯示圖像

+0

檢查圖像的分辨率要顯示。如果高度大於寬度,則以縱向模式顯示圖像。否則以橫向模式顯示圖像。這對你有幫助嗎? – WELLCZECH

+0

不可能我想以縱向模式顯示圖像iitself – achu

+0

ImageView無法檢測圖像是否被捕獲到縱向或橫向。 ImageView只能管理如何在提供的空間中顯示圖像(填充,適合,...) – WELLCZECH

回答

1

嗨看看下面的代碼。在保存拍攝的圖像之前,請執行以下步驟。它將以縱向模式保存圖像。希望這會幫助你。

int rotation = -1; 
rotation = ((WindowManager)getSystemService(Context.WINDOW_SERVICE)) 
       .getDefaultDisplay().getOrientation(); 



    Matrix rotator = new Matrix(); 
    switch (rotation) { 
    case (Surface.ROTATION_0): 
     break; 
    case (Surface.ROTATION_90): 
     rotator.postRotate(270); 
     break; 
    case (Surface.ROTATION_180): 
     rotator.postRotate(180); 
     break; 
    case (Surface.ROTATION_270): 
     rotator.postRotate(90); 
     break; 


    // screen_{width,height} are applied before the rotate, so we don't 
    // need to change them based on rotation. 
    bmp_ss = Bitmap.createBitmap(bmp_ss, 0, 0, screen_width, screen_height, rotator, false); 
+0

whats rotation hhere – achu

+0

看到我編輯的答案。 – itsrajesh4uguys