How Capture Picture while mobile vision api - face tracking

后端 未结 2 1590
眼角桃花
眼角桃花 2021-01-06 06:30

I\'m using the Mobile vision api\'s face tracking example and i\'m trying to take picture with tapping on the screen. Firstly i wanted to take any picture on the screen with

2条回答
  •  Happy的楠姐
    2021-01-06 07:18

    Less lines of code

                        @Override
                        public void onPictureTaken(byte[] bytes) {
                            Log.d(TAG, "onPictureTaken - jpeg");
                            capturePic(bytes);
                        }
    
                        private void capturePic(byte[] bytes) {
                            try {
                                String mainpath = getExternalStorageDirectory() + separator + "MaskIt" + separator + "images" + separator;
                                File basePath = new File(mainpath);
                                if (!basePath.exists())
                                    Log.d("CAPTURE_BASE_PATH", basePath.mkdirs() ? "Success": "Failed");
                                File captureFile = new File(mainpath + "photo_" + getPhotoTime() + ".jpg");
                                if (!captureFile.exists())
                                    Log.d("CAPTURE_FILE_PATH", captureFile.createNewFile() ? "Success": "Failed");
                                FileOutputStream stream = new FileOutputStream(captureFile);
                                stream.write(bytes);
                                stream.flush();
                                stream.close();
                            } catch (IOException e) {
                                e.printStackTrace();
                            }
                        }
    
                        private String getPhotoTime(){
                            SimpleDateFormat sdf=new SimpleDateFormat("ddMMyy_hhmmss");
                            return sdf.format(new Date());
                        }
    

提交回复
热议问题