小尺寸图片问题

时间:2010-03-09 16:35:53

标签: android camera android-emulator

我在使用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 个答案:

答案 0 :(得分: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