关于自定义Camera的一些问题

来源:互联网 发布:mac解压软件 编辑:程序博客网 时间:2024/05/22 04:26

    最近在做Camera的时候出现了一点问题,这里总结一下:

   (1)照片预览时默认是横屏的怎么解?

     答案如下:

    

//首先判断手机是横屏还是竖屏,如果是竖屏就需要调整角度为90°                      if (getResources().getConfiguration().orientation != Configuration.ORIENTATION_LANDSCAPE) {// 调整预览界面角度,此方法在2.2以上mCamera.setDisplayOrientation(90);} else {mCamera.setDisplayOrientation(0);}


     (2)虽然按照(1)设置了预览角度,正常显示,但是拍出来的照片仍然是横屏的怎么破?

      答案就是设置如下:

parameter.set("orientation", "portrait");parameter.set("rotation", 90);
      注意:这两个set()方法必须同时使用啊,缺一不可,若只调用第二个设置旋转90°,会报异常的

    (3)我的图片分辨率不对,拍出来的照片很小怎么破?

      答案如下:

                        parameter.setPreviewSize(mPoint.y, mPoint.x); // 设置预览尺寸parameter.setPictureSize(mPoint.y, mPoint.x); // 设置保存的图片尺寸parameter.setJpegQuality(80); // 设置照片质量
      楼主在做的时候就碰到这个问题啊!坑爹啊,当时拍出来的照片很小很模糊有木有,然后看API找到个setPictureSize()以为找到解决方法了有木有!然后设置和屏幕分辨率一样大直接报错了有木有!在看下setPictureSize()源码注释说: Applications need to consider the display orientation. see setPreviewSize(int,int)。也就是说,setPictureSize()需要考虑到setPreviewSize()的尺寸!楼主很激动以为这下好了,然后就又调用setPreviewSize()设置和手机屏幕大小,结果又报错有木有!楼主一看注释,别人说的很清楚啊:      

Sets the dimensions for preview pictures. If the preview has already started, applications should stop the preview first before changing preview size. The sides of width and height are based on camera orientation. That is, the preview size is the size before it is rotated by display orientation. So applications need to consider the display orientation while setting preview size. For example, suppose the camera supports both 480x320 and 320x480 preview sizes. The application wants a 3:2 preview ratio. If the display orientation is set to 0 or 180, preview size should be set to 480x320. If the display orientation is set to 90 or 270, preview size should be set to 320x480. The display orientation should also be considered while setting picture size and thumbnail size.

大致意思就是说:为预览图片设置尺寸,如果已经开始了预览,那就要先停止预览然后才能改变预览尺寸。预览只存的宽度和高度是一句Camera的方向的,也就是说,预览的尺寸是旋转之前的尺寸,所以呢,在设置预览尺寸的时候应用必须考虑Display Oritentaion,比如:如果相机支持480*320和320*480,预览尺寸,应用想要一个3:2的比例,如果此时Display Oritentaion被设置为0和180°,预览尺寸就应该设置为480*320,如果Display Oritentaion设置为90或270,预览尺寸应该设置为320*480。在项目中,由于已经将相机旋转了90°,所以在调用setPreviewSize()的时候,两个参数应该为height和width!
0 0