search

Home  >  Q&A  >  body text

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();
            }
        }
    }
}
怪我咯怪我咯2845 days ago2707

reply all(1)I'll reply

  • PHP中文网

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

    Parameters params = mCamera.getParameters();
    if (!Config.FOR_MTK) {
        params.setFocusMode(Parameters.FOCUS_MODE_AUTO);
    } 
    params.setPictureSize(1920, 1080);
    mCamera.setParameters(params);
    mCamera.takePicture(mShutterCallback, mRawPictureCallback,
    mPostViewPictureCallback, mJpegPictureCallback);

    I wrote it like this, but the maximum resolution of the photo is written at the bottom of Android, so the resolution written here is modified within the maximum resolution range.

    reply
    0
  • Cancelreply