0

ユーザーが画像をキャプチャできる 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");
        }

しかし残念なことに、これをすべて行った後、静止画像はフルサイズではなく、常に横向きになります。

4

1 に答える 1

0

コードに小さな間違いがあります。画像を回転させる角度を取得したら、postRotate でこの値を使用する必要があります。

次の行を置き換えてください: mat.postRotate(90);

with: mat.postRotate(角度);

お役に立てば幸いです:-)

よろしく、ウッディ。

于 2013-07-25T11:41:59.027 に答える