I am looking at the FaceDetection example from ML Kit and I want to copy the face (perhaps using the GraphicOverlay?) of the recognized person. Is there any way to do it? I am not only interested in the face landmarks, but in the actual face itself.
I tried this (I used this method in the GraphicOverlay class and then called it in the FaceDetectionProcessor class first thing on the onSuccess method, but I get back an empty "white" jpeg when I try to save it internally):
public Bitmap getBitmapFromView(GraphicOverlay view) {
//Define a bitmap with the same size as the view
Bitmap returnedBitmap = Bitmap.createBitmap(view.getWidth(), view.getHeight(), Bitmap.Config.ARGB_8888);
//Bind a canvas to it
Canvas canvas = new Canvas(returnedBitmap);
//Get the view's background
Drawable bgDrawable =view.getBackground();
if (bgDrawable!=null) {
//has background drawable, then draw it on the canvas
bgDrawable.draw(canvas);
} else{
//does not have background drawable, then draw white background on the canvas
canvas.drawColor(Color.WHITE);
}
// draw the view on the canvas
view.draw(canvas);
//return the bitmap
return returnedBitmap;
}