0

我正在查看 ML Kit 中的 FaceDetection 示例,我想复制已识别人的面部(可能使用 GraphicOverlay?)。有什么办法吗?我不仅对面部标志感兴趣,而且对实际的面部本身感兴趣。

我试过这个(我在 GraphicOverlay 类中使​​用了这个方法,然后在 onSuccess 方法的第一件事上在 FaceDetectionProcessor 类中调用它,但是当我尝试在内部保存它时得到一个空的“白色”jpeg):

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;

}

识别的真实面孔

4

0 回答 0