【问题标题】:android image capture always landscape and not full sizeandroid图像捕获总是横向而不是全尺寸
【发布时间】:2013-03-01 15:24:02
【问题描述】:

我想在我的 Android 应用中添加图像捕捉功能,用户可以在其中捕捉图像,我正在使用以下代码:

public void open_camera() { 
    Intent intent = new Intent("android.media.action.IMAGE_CAPTURE");

    try {
        // place where to store camera taken picture
        photo = this.createTemporaryFile("picture", ".jpg");
        photo.delete();
    } catch(Exception e) {
        Toast.makeText(this, "Please check SD card! Image shot is impossible!", 10000);   
    }
    mImageUri = Uri.fromFile(photo);
    intent.putExtra(MediaStore.EXTRA_OUTPUT, mImageUri);
    //start camera intent
    startActivityForResult(intent,SELECT_PICTURE_CAMERA );

    //Intent cameraIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE); 
    //startActivityForResult(cameraIntent, SELECT_PICTURE_CAMERA); 
}

private File createTemporaryFile(String part, String ext) throws Exception {
    File tempDir= Environment.getExternalStorageDirectory();
    tempDir=new File(tempDir.getAbsolutePath()+"/.temp/");
    if(!tempDir.exists()) {
        tempDir.mkdir();
    }
    return File.createTempFile(part, ext, tempDir);
}

当我检索时

case SELECT_PICTURE_CAMERA:
    if(resultCode == RESULT_OK) {
        // Toast.makeText(this,"Camera" + imageReturnedIntent.getStringExtra(ZBarConstants.SCAN_RESULT), Toast.LENGTH_LONG).show();
        //this.yourSelectedImage = (Bitmap) imageReturnedIntent.getExtras().get("data");
        /*
        ImageButton imgbtn = (ImageButton) findViewById(R.id.imageButton_Photo);
        BitmapDrawable background = new BitmapDrawable(this.yourSelectedImage);
        imgbtn.setBackgroundDrawable(background);
        */

        try {
            File f=new File(mImageUri.getPath());

            ExifInterface exif = new ExifInterface(f.getPath());
            int orientation = exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_NORMAL);

            int angle = 0;
            if (orientation == ExifInterface.ORIENTATION_ROTATE_90) {
                angle = 90;
            } else if (orientation == ExifInterface.ORIENTATION_ROTATE_180) {
                angle = 180;
            } else if (orientation == ExifInterface.ORIENTATION_ROTATE_270) {
                angle = 270;
            }

            Matrix mat = new Matrix();
            mat.postRotate(90);

            Bitmap bmp = BitmapFactory.decodeStream(new FileInputStream(f), null, null);
            this.yourSelectedImage = Bitmap.createBitmap(bmp, 0, 0, bmp.getWidth(), bmp.getHeight(), mat, true);                 
        } catch (IOException e) {
            Log.w("TAG", "-- Error in setting image");
        } catch(OutOfMemoryError oom) {
            Log.w("TAG", "-- OOM Error in setting image");
        }

但不幸的是,在完成所有这些操作后,静止图像不是全尺寸,而且总是风景。

【问题讨论】:

    标签: android image screen-capture


    【解决方案1】:

    你的代码有一个小错误,在你得到图像应该旋转的角度后,你需要在 postRotate 中使用这个值。

    请换行: mat.postRotate(90);

    与: mat.postRotate(角度);

    希望我能帮到你:-)

    问候, 伍迪。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-02-21
      • 1970-01-01
      • 2019-08-10
      • 1970-01-01
      • 1970-01-01
      • 2019-07-07
      相关资源
      最近更新 更多