2014-12-04 110 views
0

我正在构建一个Android应用程序,我从手机的相机中单击一张照片并将其显示在ImageView中,它会自动逆时针旋转90度。我要显示它在移动点击的方向而不是让它旋转。使用相机拍摄时将图像旋转至手机的方向:Android

任何人都可以提供相关的代码片段或指向一些相关的文档?

回答

0

检查ExifInterface

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

switch(orientation) { 
case ExifInterface.ORIENTATION_ROTATE_90: 
    // rotate the image 
    break; 

    //.... 
} 
0

使用此methoh它会帮助你。

/* 
* 1 = Horizontal (normal) 
* 2 = Mirror horizontal 
* 3 = Rotate 180 
* 4 = Mirror vertical 
* 5 = Mirror horizontal and rotate 270 CW 
* 6 = Rotate 90 CW 
* 7 = Mirror horizontal and rotate 90 CW 
* 8 = Rotate 270 CW 
*/ 
public static Bitmap getRotateBitmapImage(Bitmap bm, int newHeight,int newWidth, int exifOrientation) { 
    int width = bm.getWidth(); 
    int height = bm.getHeight(); 
    float scaleWidth = ((float) newWidth)/width; 
    float scaleHeight = ((float) newHeight)/height; 
    Matrix matrix = new Matrix(); 
    matrix.postScale(scaleWidth, scaleHeight); 
    switch (exifOrientation) { 
    case ExifInterface.ORIENTATION_ROTATE_270: 
     rotate = 270; 
     break; 
    case ExifInterface.ORIENTATION_ROTATE_180: 
     rotate = 180; 
     break; 
    case ExifInterface.ORIENTATION_ROTATE_90: 
     rotate = 90; 
     break; 
    case ExifInterface.ORIENTATION_TRANSPOSE: 
     rotate = 45; 
     break; 
    case 0: 
     rotate = 360; 
     break; 
    default: 
     break; 
    } 
    matrix.postRotate(rotate); 
    // resizedBitmap = Bitmap.createScaledBitmap(bm, 65, 65, true); 
    Bitmap resizedBitmap = Bitmap.createBitmap(bm, 0, 0, width, height, matrix, false); 
    return resizedBitmap; 
} 
+0

我正在使用Intenet xyz = new Intent(Mediastore.ACTION_IMAGE_CAPTURE)来捕获图像。这种存储格式是什么格式?我如何将这里捕获的图像的对象传递给您在此描述的函数?新高度,新宽度如何? – psbits 2014-12-06 03:07:21

+0

如果您不缩放位图,则可以忽略newHeight和newWitdh部分。只需使用bitmap.getWidth()和bitmap.getHeight()。 – 2014-12-07 02:08:26

+0

您可以在Bitmap.createBitmap时删除新的高度/宽度 – samsad 2014-12-08 05:29:22

相关问题