Android 如何在摄像头预览的背景上加上一个手指可拖动的调节框?
巴扎黑
巴扎黑 2017-04-17 17:20:32
0
1
600

请问调节框该如何绘制?是在SufaceView 中绘制么?手指拖动如何实现?

启动拍照功能后,下面是摄像头预览的背景(模拟器的),在这个背景上加上一个调节框

Activity代码


public class PickActivity extends AppCompatActivity {

    private Button mBtnPick;
    private SurfaceView mSvView;

    private SurfaceHolder.Callback mCallback;
    private Camera mCamera;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_pick);
        initView();
        mCallback = new SurfaceHolder.Callback() {
            @Override
            public void surfaceCreated(SurfaceHolder holder) {
                startCamera();
            }

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

            }

            @Override
            public void surfaceDestroyed(SurfaceHolder holder) {
                stopCamera();
            }
        };
        mSvView.getHolder().addCallback(mCallback);
        mBtnPick.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                mCamera.takePicture(null, null, new Camera.PictureCallback() {
                    @Override
                    public void onPictureTaken(byte[] data, Camera camera) {
                        File path = new File(Environment.getExternalStorageDirectory(), "test");
                        if (!path.exists()) {
                            path.mkdirs();
                        }
                        File fileName = new File(path, "test.jpg");
                        try {
                            FileOutputStream fos = new FileOutputStream(fileName);
                            fos.write(data);
                            fos.flush();
                            fos.close();
                        } catch (IOException e) {
                            e.printStackTrace();
                        }
                    }
                });
            }
        });
    }

    private void stopCamera() {
        mCamera.stopPreview();
        mCamera.release();
        mCamera = null;
    }

    private void startCamera() {
        mCamera = Camera.open();
        try {
            mCamera.setPreviewDisplay(mSvView.getHolder());
            mCamera.setDisplayOrientation(90);
            mCamera.startPreview();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    private void initView() {
        mBtnPick = (Button) findViewById(R.id.id_btn_pick);
        mSvView = (SurfaceView) findViewById(R.id.id_sv_camera);
    }
}
巴扎黑
巴扎黑

Antworte allen(1)
伊谢尔伦

添加seekBar

Beliebte Tutorials
Mehr>
Neueste Downloads
Mehr>
Web-Effekte
Quellcode der Website
Website-Materialien
Frontend-Vorlage