Android相机getSupported previewSizes()错误 [英] Android Camera getSupportedPreviewSizes() error

查看:2958
本文介绍了Android相机getSupported previewSizes()错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在三星Galaxy Tab测试我的Andr​​oid应用程序。当我在平板电脑上打开摄像头应用程序,我看到你可以设置相机的可能的解决方案是:


  • 2560 X 1920

  • 2560 X 1440

  • 2048×1536

  • 2048×1152

  • 1600×1200

  • 1536点¯x864

  • 640×480

然而,当我在我的Andr​​oid应用程序打开相机实例,并获取支持preVIEW大小,我得到了如下决议:


  • 1024×768

  • 1280×720

  • 1024×576

  • 768×512

  • 640 480

  • 352×288

  • 320×240

为什么会出现在支持的分辨率这样的差异?我想我的自定义相机的活动有一个全屏幕的相机,我不能与比屏幕大小(我的应用程序说的是800 * 1344)。较小的分辨率做

  //获取屏幕尺寸
    。getWindowManager()getDefaultDisplay()getMetrics(指标)。
    INT宽度= metrics.widthPixels;
    INT高度= metrics.heightPixels + navBarHeight;
    Log.d(TAG,屏幕宽度和高度:+宽++高);    //获取支持preVIEW大小
    Camera.CameraInfo cameraInfo =新Camera.CameraInfo();
    cameraCount = Camera.getNumberOfCameras();
    对(INT camIdx = 0; camIdx&下; cameraCount; camIdx ++){
        Camera.getCameraInfo(camIdx,cameraInfo);
        如果(cameraInfo.facing == Camera.CameraInfo.CAMERA_FACING_BACK){
            尝试{
                C = Camera.open(); //试图得到一个摄像头实例
                的for(int i = 0; I< c.getParameters()getSupported previewSizes()大小();我++){
                    尺码大小= c.getParameters()getSupported previewSizes()得到(I)。
                    Log.d(TAG,支持preVIEW大小:+ size.width ++ size.height);
                }
            }赶上(例外五){
                //摄像头不可用(在使用或不存在)
                e.printStackTrace();
            }
        }否则如果(cameraCount == 1和;&放大器; cameraInfo.facing == Camera.CameraInfo.CAMERA_FACING_FRONT){
            //设备只有一个前置摄像头
            尝试{
                C = Camera.open(camIdx); //试图得到一个摄像头实例
            }赶上(例外五){
                //摄像头不可用(在使用或不存在)
                e.printStackTrace();
            }
        }
    }


解决方案

  

为什么会出现这样的差异在支持的分辨率?


照片分辨率和preVIEW分辨率不一样的东西。前者是为图片。后者是用于preVIEW帧


  

我想我的自定义相机的活动有一个全屏幕的相机,我不能与比屏幕大小(我的应用程序说的是800 * 1344)。较小的分辨率做


是的,可以。 Android将愉快地拉伸或收缩您的preVIEW帧相匹配的大小 TextureView SurfaceView 你是使用为preVIEW。事实上,这样的拉伸或收缩为pretty很多不可避免的,因为这是相当不可能的摄像头将支持一些任意preVIEW分辨率,一个恰好匹配无论你是选择适合您preVIEW 查看尺寸

I am testing my Android app on a Samsung Galaxy Tab. When I open up the camera application on the tablet, I see that the possible resolutions you can set for the camera are:

  • 2560 x 1920
  • 2560 x 1440
  • 2048 x 1536
  • 2048 x 1152
  • 1600 x 1200
  • 1536 x 864
  • 640 x 480

However, when I open up a camera instance in my Android app and fetch the supported preview sizes, I get the following resolutions:

  • 1024 x 768
  • 1280 x 720
  • 1024 x 576
  • 768 x 512
  • 640 480
  • 352 x 288
  • 320 x 240

Why is there such a discrepancy in the supported resolutions? I want my custom camera activity to have a full screen camera, and I can't do it with resolutions that are smaller than the screen size (which my app says is 800 x 1344).

    // fetch screen size
    getWindowManager().getDefaultDisplay().getMetrics(metrics);
    int width = metrics.widthPixels;
    int height = metrics.heightPixels+navBarHeight;
    Log.d(TAG, "screen width and height: " + width + " " + height);

    // get supported preview sizes
    Camera.CameraInfo cameraInfo = new Camera.CameraInfo();
    cameraCount = Camera.getNumberOfCameras();
    for(int camIdx = 0; camIdx < cameraCount; camIdx++){
        Camera.getCameraInfo( camIdx, cameraInfo );
        if(cameraInfo.facing == Camera.CameraInfo.CAMERA_FACING_BACK){
            try {
                c = Camera.open(); // attempt to get a Camera instance
                for(int i =0; i< c.getParameters().getSupportedPreviewSizes().size(); i++){
                    Size size = c.getParameters().getSupportedPreviewSizes().get(i);
                    Log.d(TAG, "supported preview size: " + size.width + " " + size.height);
                }
            } catch (Exception e) {
                // Camera is not available (in use or does not exist)
                e.printStackTrace();
            }
        } else if(cameraCount == 1 && cameraInfo.facing == Camera.CameraInfo.CAMERA_FACING_FRONT)          {
            // device only has a front facing camera
            try {
                c = Camera.open(camIdx); // attempt to get a Camera instance
            } catch (Exception e) {
                // Camera is not available (in use or does not exist)
                e.printStackTrace();
            }
        }
    }

解决方案

Why is there such a discrepancy in the supported resolutions?

Picture resolutions and preview resolutions are not the same thing. The former is for pictures. The latter is for the preview frames.

I want my custom camera activity to have a full screen camera, and I can't do it with resolutions that are smaller than the screen size (which my app says is 800 x 1344).

Yes, you can. Android will happily stretch or shrink your preview frames to match the size of the TextureView or SurfaceView that you are using for the preview. In fact, such stretching or shrinking is pretty much unavoidable, since it is rather unlikely that the camera will support some arbitrary preview resolution, one that happens to match whatever you are choosing for your preview View size.

这篇关于Android相机getSupported previewSizes()错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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