Android手机上设置摄像头分辨率机上、摄像头、分辨率、Android

2023-09-07 09:11:14 作者:︶﹉梦倾城べ

即时通讯开发一个应用程序,允许用户进行拍照,然后它做它的一些工作在后台,但是我遇到了一个问题,我已经很难codeD图像尺寸到它,它是导致错误不同的手机,一个我使用和IM假设其打倒在手机不支持摄像头的大小上,我有硬codeD。

im developing an app that allows users to take a picture and then it does some work on it in the background, however i have run into a problem i have hard coded the picture size into it and it is causing errors on a different phone to the one i am using and im assuming its down to the phone not supporting the camera size i have hard coded.

我在这里关于它的阅读,但答案是含糊所有的人一直说是使用getSupportedSizes方法,但我只是不知道该怎么以后用它做。

i have read on here about it but the answers are to vague all people keep saying is to use the getSupportedSizes method but i just dont know what to do with it after that.

任何帮助将大大AP preciated。

any help would be greatly appreciated.

推荐答案

由于在不同设备上的摄像头支持非常不同的分辨率使用这种方法是很重要的,所以,你必须指定你想出来的是什么分辨率那些可在给定的设备上。

It's important to use this method because the cameras on the different devices support very different resolutions, so, you'll have to specify what resolution you want out of the ones that are available on the given device.

伪....

    Camera.Parameters cp = mCamera.getParameters();

    List<Size> sl = cp.getSupportedPictureSizes();

//now that you have the list of supported sizes, pick one and set it back to the parameters...
   int w,h;
   for(Size s : sl){
      //if s.width meets whatever criteria you want set it to your w
      //and s.height meets whatever criteria you want for your h
      w = s.width;
      h = s.height;
      break;


   }

   cp.setPictureSize(w, h);

  mCamera.setParameters(cp);

通常认为最重要的是照片的纵横比的东西。所以,你要的W / H比为16:9或4:3,然后找到最高(或次高)的支持率质量。很显然,我不知道您的需求,所以你必须确定哪种尺寸的实际满足您的特定标准。如果您只是想最高的品质,你不关心的纵横比你通常会发现,在大小列表中的最后一项。

Usually the thing that matters most is the photo's aspect ratio. So, you'll want to compare the w/h to 16:9 or 4:3 and then find the highest (or second highest) quality at the supported ratio. Obviously, I don't know what your needs are so you'll have to determine what sizes actually meet your given criteria. If you simply want the highest quality and you don't care about the aspect ratio you'll usually find that as the last item in the list of sizes.