2015-04-15 43 views
0

相機意圖後照片分辨率問候如何知道onActivityResult

我做了一個攝像頭的意圖,傳遞文件的參數,以獲得全尺寸的圖像,我也有一個函數來縮放圖像,並將其設置在UI。

如何,我想知道用戶拍攝照片的分辨率。無論如何要知道用戶選擇的分辨率嗎?

我想知道這個原因我的應用程序崩潰在硬件設計與hiqh質量分辨率。任何高於200萬像素的照片都會使舊手機崩潰。

我知道真正的解決方案是提高整體應用程序中JAVA內存的性能。但是這將是一個quickfix,我會在稍後看到其他的。此外,1.照片的M像素就足夠了。只是不需要以質量爲核心的清單的一部分。

有無論如何知道相機使用的分辨率?

謝謝。

編輯: 謝謝大家的答案,但我不得不承認,我忽視了mi的解釋。 我想簡單獲得分辨率的另一個原因是,應用程序也會將URI路徑轉換爲內容路徑,因此如果照片的質量過高,手機將無法處理它,導致其崩潰。我只想警告用戶,如果分辨率太高,那麼我怎麼才能知道每個手機的每個適當的分辨率,而不是它,我只是捕獲錯誤「java.langOutOfMemory」,並會警告用戶。就像這樣:

try { 
//here is my method to convert uri path to content 
} catch (OutOfMemoryError outOfMemoryError) { 
          Toast toast = Toast.makeText(getApplicationContext(), "Please lower photo resolution", Toast.LENGTH_LONG); 
          toast.show(); 

         } 
+0

使用'BitmapFactory'檢查圖像,使用['inJustDecodeB ounds'只給你大小和位深度信息](http://developer.android.com/reference/android/graphics/BitmapFactory.Options.html#inJustDecodeBounds)。 – CommonsWare

+0

你停止崩潰,你應該應用insampling尺寸因子 – portfoliobuilder

+0

是的,但是如果我重新縮放圖像,我將不得不創建另一個文件從uri路徑轉換到內容路徑? – cutiko

回答

3

你可以把結果爲位圖:

Bitmap temp = BitmapFactory.decodeFile(data.getData().getPath()); 

那麼你就可以得到這樣的解決方案:

temp.getWidth(); 
    temp.getHeight(); 

,或者你可以這樣做:

BitmapFactory.Options temp = new BitmapFactory.Options(); 
    temp.inJustDecodeBounds = true; 
    BitmapFactory.decodeStream(context.getContentResolver().openInputStream(uri), null, temp); 

    int width = temp.outWidth; 
    int height = temp.outHeight;