I am capturing an image using MediaStore.ACTION_IMAGE_CAPTURE in
Android 2.1

Intent cameraintent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
File file = new File(Environment.getExternalStorageDirectory(),
"MyTestFile.jpg");
cameraintent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(file));
outputFileUri = Uri.fromFile(file);
startActivityForResult(cameraintent, CAMERA_PIC_REQUEST);

Thereafter, I am using the following function to create a new bitmap,
scaled from the existing bitmap. But I am not getting the correct
value for image orientation. As per my logic when the image has been
captured in landscape mode I should get img_orient=0 & for portrait
mode I should getimg_orient=90. But I am getting 0 for both cases.

But when I am using the same function for an existing image from
inside the media gallery, it is returning correct values i.e 0 for
landscape & 90 for portrait. Can someone please tell what is the
problem with this code?


private void setBitmap() {
    if (photoUri != null) {
        try {

            Bitmap theBmp =
MediaStore.Images.Media.getBitmap(getContentResolver(), photoUri);
            int img_orient=0;
            String[] projection =
{ MediaStore.Images.Media.ORIENTATION };
            Cursor mImageCursor = managedQuery(photoUri, projection,
"", null, null);
            if ( mImageCursor != null ) {
                mImageCursor.moveToFirst();
                img_orient =
mImageCursor.getInt(mImageCursor.getColumnIndex(MediaStore.Images.Media.ORIENTATION));
                mImageCursor.close();
            }
            // check to determine whether the image is rotated
            Toast.makeText(getApplicationContext(), "orient:
"+img_orient, Toast.LENGTH_LONG).show();
            if(img_orient==90) {
                Bitmap scaledBmp = Bitmap.createScaledBitmap(theBmp,
(dm.widthPixels-100), (dm.widthPixels-100), true);
                Matrix mat = new Matrix();
                mat.preRotate(img_orient);
                try {
                    mBitmap = Bitmap.createBitmap(scaledBmp, 0, 0,
(dm.heightPixels-50), (dm.widthPixels-100), mat, true);
                    scaledBmp.recycle();
                    scaledBmp = null;
                } catch(Exception e) {
                }
            } else {
                try {
                    mBitmap = Bitmap.createScaledBitmap(theBmp,
(dm.widthPixels-100), (dm.heightPixels-50), true);
                } catch(Exception e) {
                }
            }
            mZoomView.setImage(mBitmap);

            theBmp.recycle();
            theBmp = null;

            play_audio();
        } catch(Exception e) {
        }
    }
}

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to