2010-03-09 160 views
1

我在使用ACTION_IMAGE_CAPTURE捕獲圖片後出現了保存圖片的問題意圖圖片變得非常小,它的分辨率是27X44我使用1.5 android模擬器,這是代碼和我感謝所有幫助:小尺寸圖片問題

myImageButton02.setOnClickListener 
(
    new OnClickListener() 
    { 
     @Override 
     public void onClick(View v) 
     { 
      // create camera intent 
      Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); 
      //Grant permission to the camera activity to write the photo. 
      intent.addFlags(Intent.FLAG_GRANT_WRITE_URI_PERMISSION); 
      //saving if there is EXTRA_OUTPUT 
      intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(new File 
      (Environment.getExternalStorageDirectory(), "testExtra" + String.valueOf 
      (System.currentTimeMillis()) + ".jpg"))); 
      // start the camera intent and return the image 
      startActivityForResult(intent,1); 
     } 
    } 
); 
@Override 
protected void onActivityResult (int requestCode, int resultCode, Intent data) 
{ 
    super.onActivityResult(requestCode, resultCode, data); 

    // if Activity was canceled, display a Toast message 
    if (resultCode == RESULT_CANCELED) 
    { 
     Toast toast = Toast.makeText(this,"camera cancelled", 10000); 
     toast.show(); 
     return; 
    } 

    // lets check if we are really dealing with a picture 
    if (requestCode == 1 && resultCode == RESULT_OK) 
    { 
     String timestamp = Long.toString(System.currentTimeMillis()); 
     // get the picture 
     Bitmap mPicture = (Bitmap) data.getExtras().get("data"); 
     // save image to gallery 
     MediaStore.Images.Media.insertImage(getContentResolver(), mPicture, timestamp, timestamp); 
    } 
} 
} 
+1

@Haya,請妥善縮進代碼,以便它是可讀 – 2010-03-09 16:37:54

+0

大評論,哈雅。你的代碼現在也更容易閱讀。對不起,雖然我沒有答案,但希望有人能夠儘快提供幫助。 – 2010-03-09 18:34:32

回答

2

看看你在做什麼:

  • 您指定當您訪問的圖片您在剛剛拍攝的照片存儲與intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(new File (Environment.getExternalStorageDirectory(), "testExtra" + String.valueOf (System.currentTimeMillis()) + ".jpg")));
  • 路徑'拖'數據意圖與Bitmap mPicture = (Bitmap) data.getExtras().get("data");

顯然,你不從它的文件訪問圖片。據我所知,Intents並不是用來傳輸大量數據的,因爲它們是通過例如活動。你應該做的是從攝像機意圖創建的文件中打開圖片。看起來像這樣:

BitmapFactory.Options bitmapOptions = new BitmapFactory.Options(); 
// Limit the filesize since 5MP pictures will kill you RAM 
bitmapOptions.inSampleSize = 6; 
imgBitmap = BitmapFactory.decodeFile(pathToPicture, bitmapOptions); 

這應該做的伎倆。它曾經以這種方式爲我工作,但自從2.1在幾款設備上遇到問題。在Nexus One上工作(仍然)很好。
看看MediaStore.ACTION_IMAGE_CAPTURE

希望這會有所幫助。
問候,
Steff