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);
    }
}
}
4

1 回答 1

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");

显然,您不能从其文件中访问该图片。据我所知,Intent 并非旨在承载大量数据,因为它们是在活动之间传递的。您应该做的是从相机意图创建的文件中打开图片。看起来像这样:

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

希望这可以帮助。
问候,
斯特夫

于 2010-05-07T08:37:41.153 回答