2015-12-11 109 views
-1

我在相機中遇到了問題,圖像模糊。Android中的相機捕捉圖像不清晰(模糊)

我搜索了很多,但我不能得到解決

我不知道如何解決問題

這裏是我的代碼,我用攝像機捕獲圖像

@Override 
public void onActivityResult(int requestCode, int resultCode, Intent data) { 
    super.onActivityResult(requestCode, resultCode, data); 

    if (resultCode == Activity.RESULT_OK) { 
     if (requestCode == SELECT_FILE) 
      onSelectFromGalleryResult(data); 
     else if (requestCode == REQUEST_CAMERA) 
      onCaptureImageResult(data); 
    } 
} 

private void onCaptureImageResult(Intent data) { 
    Bitmap thumbnail = (Bitmap) data.getExtras().get("data"); 
    ByteArrayOutputStream bytes = new ByteArrayOutputStream(); 
    thumbnail.compress(Bitmap.CompressFormat.JPEG, 0, bytes); 

    File destination = new File(Environment.getExternalStorageDirectory(), 
      System.currentTimeMillis() + ".jpg"); 

    FileOutputStream fo; 
    try { 
     destination.createNewFile(); 
     fo = new FileOutputStream(destination); 
     fo.write(bytes.toByteArray()); 
     fo.close(); 
    } catch (FileNotFoundException e) { 
     e.printStackTrace(); 
    } catch (IOException e) { 
     e.printStackTrace(); 
    } 


    img1.setImageBitmap(thumbnail); 
} 

@SuppressWarnings("deprecation") 
private void onSelectFromGalleryResult(Intent data) { 
    Uri selectedImageUri = data.getData(); 
    String[] projection = {MediaStore.MediaColumns.DATA}; 
    Cursor cursor = managedQuery(selectedImageUri, projection, null, null, 
      null); 
    int column_index = cursor.getColumnIndexOrThrow(MediaStore.MediaColumns.DATA); 
    cursor.moveToFirst(); 

    String selectedImagePath = cursor.getString(column_index); 

    Bitmap bm; 
    BitmapFactory.Options options = new BitmapFactory.Options(); 
    options.inJustDecodeBounds = true; 
    BitmapFactory.decodeFile(selectedImagePath, options); 
    final int REQUIRED_SIZE = 200; 
    int scale = 1; 
    while (options.outWidth/scale/2 >= REQUIRED_SIZE 
      && options.outHeight/scale/2 >= REQUIRED_SIZE) 
     scale *= 2; 
    options.inSampleSize = scale; 
    options.inJustDecodeBounds = false; 
    bm = BitmapFactory.decodeFile(selectedImagePath, options); 

    img1.setImageBitmap(bm); 

} 

圖像集圖像集在Imageview中良好,但它僅在攝像頭拍攝時發生Imageview Camera Capture Image is not clear(Blurry) in Android

幫助我t他的問題。

在此先感謝

回答

0

你在做什麼越來越縮略圖釘子出來,這就是爲什麼它是模糊

意圖數據的嘗試: 文件mImageFile是要你存儲的攝像機圖像文件的路徑。

mImageFile= new File(Environment.getExternalStorageDirectory() + File.separator + "DCIM" + File.separator + "temp.png"); 

Uri tempURI = Uri.fromFile(mImageFile); 
Intent i = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); 
i.putExtra(MediaStore.EXTRA_OUTPUT, tempURI); 
activity.startActivityForResult(i, CHOOSE_CAMERA_RESULT); 


then in your onActivityResult 

@Override 
public void onActivityResultRAW(int requestCode, int resultCode, Intent data) 
{ 
    super.onActivityResultRAW(requestCode, resultCode, data); 
    switch(requestCode) 
    { 
    case CHOOSE_CAMERA_RESULT: 
    { 
     if (resultCode == RESULT_OK) 
     { 
      // here you image has been save to the path mImageFile. 
      Log.d("ImagePath", "Image saved to path : " + mImageFile.getAbsoultePath()); 
     } 
    } 
    break; 
    } 
} 
+0

我有兩個選項圖庫或相機SO我如何修改它。幫我到Modifi這。@ dex –

+0

Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); startActivityForResult(intent,REQUEST_CAMERA);我用這個Open Camera @dex –

+0

@RushangPrajapati:一旦你點擊相機按鈕,調用startCamera活動代碼,一旦點擊結束,然後在OnActivityResult中,你可以得到相應的圖像...過程。對於圖庫,您可以通過Intent調用圖庫intent = new Intent(Intent.ACTION_GET_CONTENT); intent.addCategory(Intent.CATEGORY_OPENABLE); intent.setType(「image/*」); startActivityForResult(intent,Gallery_code),然後在onActivityResult中,您將從該uri獲取URI,openInputStream以獲取圖像的位圖。 – dex

0

您的問題是在這裏.compress

thumbnail.compress(Bitmap.CompressFormat.JPEG, 0, bytes); 

第二paramater()方法是質量其可以是範圍0..100。 您已將其設置爲0 - >最大壓縮。

將該值更改爲更高的值。

相關問題