찾다

 >  Q&A  >  본문

android - SurfaceView 拍照,怎么设置分辨率

1.华为荣耀4a测试,分辨率一直是160*120?
2.求助
代码如下:

 SurfaceHolder holder;
    Camera cam;
    Camera.Parameters myParameters;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_photo);
        initView();
    }

    private void initView() {
        //双缓冲view
        SurfaceView sfv= (SurfaceView) findViewById(R.id.surfaceView);

        ViewGroup.LayoutParams lp = sfv.getLayoutParams();
        lp.width = 750;
        lp.height =1200;
        sfv.setLayoutParams(lp);
        //帮助类对象
        holder = sfv.getHolder();
        //指定类型
        holder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
        //指定回调接口
        holder.addCallback(new A());

    }
    private class A implements SurfaceHolder.Callback {
        @Override
        public void surfaceCreated(SurfaceHolder holder) {

            cam = Camera.open(0);
            try {
                myParameters = cam.getParameters();
                myParameters.setPreviewFpsRange(20, 40);
                myParameters.setPictureFormat(ImageFormat.JPEG);
                myParameters.set("jpeg-quality", 85);
             //   myParameters.setPictureSize(750, 1280);

                cam.setPreviewDisplay(holder);
                cam.setDisplayOrientation(90);
               // cam.setParameters(myParameters);
                cam.startPreview();


            } catch (Exception e) {
                e.printStackTrace();
            }
        }

        @Override
        public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) {

        }

        @Override
        public void surfaceDestroyed(SurfaceHolder holder) {

        }
    }
    public void take(View v){
        //创建图片
        cam.takePicture(null,null,new B());
    }

    private class B implements Camera.PictureCallback {

        @Override
        public void onPictureTaken(byte[] data, Camera camera) {
            try {
                Bitmap a= BitmapFactory.decodeByteArray(data,0,data.length);

                //当前时间的毫秒数
                long time = System.currentTimeMillis();
                String  path="/sdcard/"+time+".jpg";
                FileOutputStream out=new FileOutputStream(new File(path));
                //压缩
                a.compress(Bitmap.CompressFormat.JPEG,100,out);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }
}
怪我咯怪我咯2771일 전2638

모든 응답(1)나는 대답할 것이다

  • PHP中文网

    PHP中文网2017-04-18 09:09:25

    으아악

    이렇게 썼는데 안드로이드 하단에 사진 최대 해상도가 적혀있어서 여기에 적힌 해상도도 최대해상도 범위 내에서 수정했습니다.

    회신하다
    0
  • 취소회신하다