【问题标题】:Android: Bitmap image get reversed in Preview?Android:位图图像在预览中反转?
【发布时间】:2012-06-29 17:23:00
【问题描述】:

我用 camera.take picture 拍照,然后将这些数据输入到照片中并转换为位图。然后我在 imageview 中显示。

当我以横向模式拍照时,一切正常。如果我以纵向模式拍照,则预览图像会反转。请帮我解决这个问题。

提前谢谢....

【问题讨论】:

    标签: android bitmap android-camera android-imageview


    【解决方案1】:

    这个link 完全回应了你提到的内容

    public static void setCameraDisplayOrientation(Activity activity,
             int cameraId, android.hardware.Camera camera) {
         android.hardware.Camera.CameraInfo info =
                 new android.hardware.Camera.CameraInfo();
         android.hardware.Camera.getCameraInfo(cameraId, info);
         int rotation = activity.getWindowManager().getDefaultDisplay()
                 .getRotation();
         int degrees = 0;
         switch (rotation) {
             case Surface.ROTATION_0: degrees = 0; break;
             case Surface.ROTATION_90: degrees = 90; break;
             case Surface.ROTATION_180: degrees = 180; break;
             case Surface.ROTATION_270: degrees = 270; break;
         }
    
         int result;
         if (info.facing == Camera.CameraInfo.CAMERA_FACING_FRONT) {
             result = (info.orientation + degrees) % 360;
             result = (360 - result) % 360;  // compensate the mirror
         } else {  // back-facing
             result = (info.orientation - degrees + 360) % 360;
         }
         camera.setDisplayOrientation(result);
     }
    

    【讨论】:

    • 感谢您的快速回答...但这适用于 android 4... 但我在 android 2.1 上工作...
    • @Siva 如果您想使用低 api,您可以使用应用程序的向后兼容性。 Android 是开源的,您可以获取该功能的源代码并将其作为库添加到您的项目中
    猜你喜欢
    • 2013-12-30
    • 1970-01-01
    • 2018-09-16
    • 1970-01-01
    • 2018-08-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多