2017-10-11 125 views
0

我目前正在做一個故障報告頁面,最終用戶可以通過捕獲使用相機或從相冊中選擇一張照片來報告image。我不知道爲什麼,但是當image使用相機拍攝時,返回的heightwidth大約是220180,這是一個非常模糊的圖像。我曾嘗試在網上尋找其他教程,但我的代碼似乎與其他教程相同。不太確定它是我的手機還是什麼。Android相機高度和寬度

我的相機意向代碼:

Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); 
startActivityForResult(intent, REQUEST_CAMERA); 

從攝像頭捕獲圖像之後,我的代碼:

thumbnail = (Bitmap) data.getExtras().get("data"); 
bytes = new ByteArrayOutputStream(); 
thumbnail.compress(Bitmap.CompressFormat.JPEG, 100, bytes); 

ivImage.setVisibility(View.VISIBLE); 
ivImage.setImageBitmap(thumbnail); 

我已經試過壓縮前後得到widthheight,都返回相同的值。

+0

請不要標記過Android Studio,除非這不是Android的工作室 – UltimateDevil

+0

問題的問題與凸輪pixels.Change,在相機應用。 – Anonymous

+0

已經在16:9,5312x2988。降低到4:3確實有幫助,但像素增加了20到30個。 – user3567749

回答

0

可能是你不應該壓縮的圖像,而只需使用​​或從文件中獲取圖像爲bitmap任何合適的方法(如果尚未完成),然後設置位圖對象的ImageResource這樣的:

Bitmap bitmap = BitmapFactory.decodeFile(filePath); 
mImageView.setImageBitmap(bitmap); 

而不要簡單地輸入從意圖收到的數據。就我所瞭解的相機活動類而言,它會返回捕獲圖像的URI。試着接受它在onActivityResult()這樣的:

@Override 
    protected void onActivityResult(int requestCode, int resultCode, Intent data) { 
     if (resultCode != RESULT_OK) return; 

     if (requestCode == REQUEST_CAMERA) { 
      Uri photoUri = data.getData(); 
      // Calculate the bitmap here according to the width of the device 
      ((ImageView) findViewById(R.id.captured_image)).setImageBitmap(bitmap); 
     } 
     super.onActivityResult(requestCode, resultCode, data); 
    }