android - SurfaceView 拍照,怎么设置分辨率
怪我咯
怪我咯 2017-04-18 09:07:25
0
1
2663

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

走同样的路,发现不同的人生

répondre à tous(1)
Ty80
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);

Je l'ai écrit comme ça, mais la résolution maximale de la photo est écrite en bas d'Android, donc la résolution écrite ici est modifiée dans la plage de résolution maximale.

Derniers téléchargements
Plus>
effets Web
Code source du site Web
Matériel du site Web
Modèle frontal