如何从此处将FirebaseVisionFace转换为位图?

时间:2019-06-27 15:38:03

标签: android firebase-mlkit

我实现了Firebase ML工具包,你们可以帮助我如何根据这些信息创建位图并将其显示给imageview?请帮助我如何在此阶段创建位图并将其保存到设备内存中?我尝试了这段代码,帮助我更深入。

fn2<Tree, "age">(tree, dog); // error, dog is not a StrictPicked<Tree, "age">

1 个答案:

答案 0 :(得分:0)

您可以执行以下操作:

    // bitmap is the image you already detected faces

    Paint myRectPain = new Paint();
    myRectPain.setStrokeWidth(10);
    myRectPain.setColor(Color.RED);
    myRectPain.setStyle(Paint.Style.STROKE);

    Bitmap tempBitmap = Bitmap.createBitmap(bitmap.getWidth(), bitmap.getHeight(),Bitmap.Config.RGB_565);

    Canvas tempCanvas = new Canvas(tempBitmap);
    tempCanvas.drawBitmap(bitmap,0,0,null);

    for (FirebaseVisionFace face: faces) {
        Rect bound = face.getBoundingBox();
        tempCanvas.drawRect(bound,myRectPain);
    }

    // imgView is an ImageView

    imgView.setImageDrawable(new BitmapDrawable(getResources(),tempBitmap));