Android 如何在摄像头预览的背景上加上一个手指可拖动的调节框?
问题描述
请问调节框该如何绘制?是在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); }}
问题解答
回答1:添加seekBar
相关文章:
1. docker images显示的镜像过多,狗眼被亮瞎了,怎么办?2. angular.js - angular内容过长展开收起效果3. macos - mac下docker如何设置代理4. docker-compose 为何找不到配置文件?5. 在windows下安装docker Toolbox 启动Docker Quickstart Terminal 失败!6. 在mac下出现了两个docker环境7. PHP中的$this代表当前的类还是方法?8. dockerfile - [docker build image失败- npm install]9. java - 我用Tomcat访问SQL server数据库时,出现以下错误,该怎么解决?10. docker绑定了nginx端口 外部访问不到