简体   繁体   中英

How to donwload image to gallery after FACE DETECTED in Android?

I can detect faces by the help of Google's sample vision app FaceTracker . What I want to do is to take photo of detected face and download it to phone Gallery.

File imagesFolder = new File( Environment.getExternalStorageDirectory() , "FolderName" );
            imagesFolder.mkdirs();
            final File image = new File( imagesFolder , "/" + "IMG_" +System.currentTimeMillis() + ".png" );
            File file = new File( Environment.getExternalStorageDirectory() + "/" + System.currentTimeMillis() + ".png");
            imgCap.takePicture(image, new ImageCapture.OnImageSavedListener() {
                @Override
                public void onImageSaved(@NonNull File file) {
                    String msg = "Pic captured at " + image.getAbsolutePath();

                    //storing the image in a folder in gallery  

                    Intent mediaScanIntent = new Intent( Intent.ACTION_MEDIA_SCANNER_SCAN_FILE );
                    Uri contentUri = Uri.fromFile( image );
                    mediaScanIntent.setData( contentUri );
                   getActivity().sendBroadcast( mediaScanIntent );

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM