我在Android中使用谷歌API进行脸部检测。当检测到脸部时,我在画布上绘制图像。我试图通过单击按钮捕获覆盖图像。在方法中
public void onPictureTaken(byte[] bytes)
,字节仅包含没有在其上绘制叠加的图像。有没有办法用叠加层保存图像?
答案 0 :(得分:0)
你必须
创建一个由新位图支持的新画布
Bitmap picture = BitmapFactory.decodeByteArray(bytes, 0, bytes.length);
Bitmap resizedBitmap = Bitmap.createBitmap(mGraphicOverlay.getWidth(),mGraphicOverlay.getHeight(),picture.getConfig());
Canvas canvas = new Canvas(resizedBitmap);
在上面绘制捕获的位图
另外,为了使叠加层与捕获的图像匹配,您需要镜像图像或叠加层
Matrix matrix = new Matrix();
matrix.setScale((float)resizedBitmap.getWidth()/(float)picture.getWidth(),(float)resizedBitmap.getHeight()/(float)picture.getHeight());
// mirror by inverting scale and translating
matrix.preScale(-1, 1);
matrix.postTranslate(canvas.getWidth(), 0);
Paint paint = new Paint();
canvas.drawBitmap(picture,matrix,paint);
tracker.getmEyesGraphic().draw(canvas); // make those accessible