拍摄的照片旋转三星移动90度 [英] Capture photo rotate 90 degree in samsung mobile

查看:139
本文介绍了拍摄的照片旋转三星移动90度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

照片旋转90度,而从相机的​​其他手机(HTC),其做工精致三星移动休息捕捉。请帮我的。

 意图cameraIntent =新的意图(android.provider.MediaStore.ACTION_IM​​AGE_CAPTURE);
startActivityForResult(cameraIntent,IMAGE_CAPTURE);

@覆盖
 保护无效onActivityResult(INT申请code,INT结果code,意图数据){
    super.onActivityResult(要求code,因此code,数据);
      尝试
    {
    如果(要求code == IMAGE_CAPTURE){
       如果(结果code == RESULT_OK){

       乌里contentUri = data.getData();
       如果(contentUri!= NULL)
       {
        的String []凸出= {MediaStore.Images.Media.DATA};
            光标光标= managedQuery(contentUri,凸出,NULL,NULL,NULL);
        INT与Column_Index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
        cursor.moveToFirst();
        imageUri = Uri.parse(cursor.getString(Column_Index中));
       }

       。tempBitmap =(位图)data.getExtras()获得(数据);
       mainImageView.setImageBitmap(tempBitmap);
       isCaptureFromCamera = TRUE;
    }
 }
 

解决方案

某些设备,根据设备的方向旋转图像。

在这里我有写一个通用的方法来获得方向,让图像在右轴

 公共位图德codeFILE(字符串路径){//你可以在这里提供的文件路径
        INT方向;
        尝试 {
            如果(路径== NULL){
                返回null;
            }
            //德code图像尺寸
            BitmapFactory.Options O =新BitmapFactory.Options();
            o.inJustDe codeBounds = TRUE;
            //找到正确的比例值。它应该是2的幂。
            最终诠释REQUIRED_SIZE = 70;
            INT width_tmp = o.outWidth,height_tmp = o.outHeight;
            int标= 0;
            而(真){
                如果(width_tmp / 2'; REQUIRED_SIZE
                        || height_tmp / 2版; REQUIRED_SIZE)
                    打破;
                width_tmp / = 2;
                height_tmp / = 2;
            规模++;
            }
            //德code与inSampleSize
            BitmapFactory.Options O2 =新BitmapFactory.Options();
            o2.inSampleSize =规模;
            位图BM = BitmapFactory.de codeFILE(路径,O2);
            点阵位图= BM;

            ExifInterface EXIF​​ =新ExifInterface(路径);

            方向= EXIF
                    .getAttributeInt(ExifInterface.TAG_ORIENTATION,1);

            Log.e(ExifInteface .........,旋转=+方向);

// exif.setAttribute(ExifInterface.ORIENTATION_ROTATE_90,90);

            Log.e(方向,+方向);
            矩阵M =新的Matrix();

            如果((取向== ExifInterface.ORIENTATION_ROTATE_180)){
                m.postRotate(180);
// m.postScale((浮点)bm.getWidth(),(浮动)bm.getHeight());
                //如果(米。preRotate(90)){
                Log.e(定向,+方向);
                位图= Bitmap.createBitmap(宽多重峰,0,0,bm.getWidth(),
                        bm.getHeight(),男,真正的);
                返回的位图;
            }否则,如果(定向== ExifInterface.ORIENTATION_ROTATE_90){
                m.postRotate(90);
                Log.e(定向,+方向);
                位图= Bitmap.createBitmap(宽多重峰,0,0,bm.getWidth(),
                        bm.getHeight(),男,真正的);
                返回的位图;
            }
            否则,如果(定向== ExifInterface.ORIENTATION_ROTATE_270){
                m.postRotate(270);
                Log.e(定向,+方向);
                位图= Bitmap.createBitmap(宽多重峰,0,0,bm.getWidth(),
                        bm.getHeight(),男,真正的);
                返回的位图;
            }
            返回的位图;
        }赶上(例外五){
            返回null;
        }

    }
 

编辑:

这code不是最优化的,我只是表明从我的测试项目中的一个逻辑code。

Photo is rotating 90 degree while capturing from camera in samsung mobile rest of other mobiles(HTC) its working fine. Please help me for this.

Intent cameraIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(cameraIntent, IMAGE_CAPTURE); 

@Override 
 protected void onActivityResult(int requestCode, int resultCode, Intent data) {     
    super.onActivityResult(requestCode, resultCode, data);    
      try
    {
    if (requestCode == IMAGE_CAPTURE) {
       if (resultCode == RESULT_OK){

       Uri contentUri = data.getData();
       if(contentUri!=null)
       {
        String[] proj = { MediaStore.Images.Media.DATA };         
            Cursor cursor = managedQuery(contentUri, proj, null, null, null);         
        int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);         
        cursor.moveToFirst();         
        imageUri = Uri.parse(cursor.getString(column_index));
       }

       tempBitmap = (Bitmap) data.getExtras().get("data"); 
       mainImageView.setImageBitmap(tempBitmap);
       isCaptureFromCamera = true;
    }
 }

解决方案

Some device rotate image according to device orientation .

here i have write one common method to get orientation and get image in right scale

    public  Bitmap decodeFile(String path) {//you can provide file path here 
        int orientation;
        try {
            if (path == null) {
                return null;
            }
            // decode image size 
            BitmapFactory.Options o = new BitmapFactory.Options();
            o.inJustDecodeBounds = true;
            // Find the correct scale value. It should be the power of 2.
            final int REQUIRED_SIZE = 70;
            int width_tmp = o.outWidth, height_tmp = o.outHeight;
            int scale = 0;
            while (true) {
                if (width_tmp / 2 < REQUIRED_SIZE
                        || height_tmp / 2 < REQUIRED_SIZE)
                    break;
                width_tmp /= 2;
                height_tmp /= 2;
            scale++;
            }
            // decode with inSampleSize
            BitmapFactory.Options o2 = new BitmapFactory.Options();
            o2.inSampleSize = scale;
            Bitmap bm = BitmapFactory.decodeFile(path, o2);
            Bitmap bitmap = bm;

            ExifInterface exif = new ExifInterface(path);

            orientation = exif
                    .getAttributeInt(ExifInterface.TAG_ORIENTATION, 1);

            Log.e("ExifInteface .........", "rotation ="+orientation);

//          exif.setAttribute(ExifInterface.ORIENTATION_ROTATE_90, 90);

            Log.e("orientation", "" + orientation);
            Matrix m = new Matrix();

            if ((orientation == ExifInterface.ORIENTATION_ROTATE_180)) {
                m.postRotate(180);
//              m.postScale((float) bm.getWidth(), (float) bm.getHeight());
                // if(m.preRotate(90)){
                Log.e("in orientation", "" + orientation);
                bitmap = Bitmap.createBitmap(bm, 0, 0, bm.getWidth(),
                        bm.getHeight(), m, true);
                return bitmap;
            } else if (orientation == ExifInterface.ORIENTATION_ROTATE_90) {
                m.postRotate(90); 
                Log.e("in orientation", "" + orientation);
                bitmap = Bitmap.createBitmap(bm, 0, 0, bm.getWidth(),
                        bm.getHeight(), m, true);
                return bitmap;
            }
            else if (orientation == ExifInterface.ORIENTATION_ROTATE_270) {
                m.postRotate(270);
                Log.e("in orientation", "" + orientation);
                bitmap = Bitmap.createBitmap(bm, 0, 0, bm.getWidth(),
                        bm.getHeight(), m, true);
                return bitmap;
            } 
            return bitmap;
        } catch (Exception e) {
            return null;
        }

    }

EDIT:

This code is not optimized , i just show the logic code from my one of the test project.

这篇关于拍摄的照片旋转三星移动90度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆