android 自定义相机画面倒立解决方案

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
有部分手机的影像是倒立的,如何解决这个问题呢? 请看下面 
       
    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); 
     
     @Override 
        public void surfaceChanged(SurfaceHolder arg0, int arg1, int arg2, int arg3) { 
            // TODO Auto-generated method stub 
                         setCameraDisplayOrientation(this,0,camera) 
 
        }
posted @   请叫我码农怪蜀黍  阅读(960)  评论(0编辑  收藏  举报
编辑推荐:
· 对象命名为何需要避免'-er'和'-or'后缀
· SQL Server如何跟踪自动统计信息更新?
· AI与.NET技术实操系列:使用Catalyst进行自然语言处理
· 分享一个我遇到过的“量子力学”级别的BUG。
· Linux系列:如何调试 malloc 的底层源码
阅读排行:
· C# 中比较实用的关键字,基础高频面试题!
· .NET 10 Preview 2 增强了 Blazor 和.NET MAUI
· 为什么AI教师难以实现
· 如何让低于1B参数的小型语言模型实现 100% 的准确率
· AI Agent爆火后,MCP协议为什么如此重要!
点击右上角即可分享
微信分享提示