图像拉伸默认拍摄的相机?

时间:2014-09-29 08:54:11

标签: android android-camera

嗨我使用默认相机拍摄我的应用程序,但在拍照后,照片尺寸被拉伸。使用默认相机获取原始图像尺寸。

1 个答案:

答案 0 :(得分:0)

从相机拍摄照片并执行data.getData()时,会返回缩略图图像。这就是拉伸的原因。 要获得完整图像,您需要为相机意图中的图像传递Uri,以使用它来获取完整图像。

例如: -

try {
        Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);

        if (takePictureIntent.resolveActivity(mContext.getPackageManager()) != null) {

            createImageFile();

            takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT,userPhotoUri);
            startActivityForResult(takePictureIntent, Utils.ACTION_REQUEST_CAMERA);

        }
    } catch (Exception e) {
                    CustomizeCrouton.showCrouton("Capture Photo cannot be launched.", mContext);
}

方法createImageFile()返回用于存储捕获图像的URI: -

private void createImageFile() throws IOException {

    File image = null;

    // Create an image file name
    String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date());
    String imageFileName = "JPEG_" + timeStamp + "_";

    if(MEDIA_MOUNTED.equals(Environment.getExternalStorageState())){

        File storageDir = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES);
        image = File.createTempFile(
                imageFileName,  /* prefix */
                ".jpg",         /* suffix */
                storageDir      /* directory */
                );

    }else{

        File storageDir = mContext.getFilesDir();
        image = File.createTempFile(
                imageFileName,  /* prefix */
                ".jpg",         /* suffix */
                storageDir      /* directory */
                );

    }

    // Save a file: path for use with ACTION_VIEW intents
    Log.d(TAG,"file:" + image.getAbsolutePath());
    userPhotoUri = Uri.fromFile(image);
}

拍摄图像后,使用该Uri加载图像。为此,有很多方法,你可以谷歌: -

 Bitmap bitmap = MediaStore.Images.Media.getBitmap(this.getContentResolver(), imageUri);
相关问题