为什么绘制的脸部矩形,位置显示不正确。显示在头上,而不再脸上?
为什么绘制的脸部矩形,位置显示不正确。显示在头上,而不再脸上?
private void drawBitmap(Bitmap bitmap, FaceDetail detail) { Bitmap createBitmap = Bitmap.createBitmap(bitmap.getWidth(), bitmap.getHeight(), bitmap.getConfig()); int bitmapWidth = createBitmap.getWidth(); int bitmapHeight = createBitmap.getHeight(); Canvas canvas = new Canvas(createBitmap); Paint paint = getPaint(bitmap); canvas.drawBitmap(bitmap, 0, 0, null); float center_x = (float) detail.getFace().get(0).getPosition() .getCenter().getX(); float center_y = (float) detail.getFace().get(0).getPosition() .getCenter().getY(); float image_width = (float) detail.getFace().get(0).getPosition() .getWidth(); float image_height = (float) detail.getFace().get(0).getPosition() .getHeight(); float face_with = (float) (image_width / 100 * bitmapWidth); float face_height = (float) (image_height / 100 * bitmapHeight); float center_width = (float) (center_x / 100 * bitmapWidth); float center_height = (float) (center_y / 100 * bitmapHeight); canvas.drawLine(center_width - face_with/2, center_y - face_height/2, center_width + face_with/2, center_y - face_height/2, paint); canvas.drawLine(center_width - face_with/2, center_y - face_height/2, center_width - face_with/2, center_y + face_height/2, paint); canvas.drawLine(center_width + face_with/2, center_y + face_height/2, center_width + face_with/2, center_y - face_height/2, paint); canvas.drawLine(center_width + face_with/2, center_y + face_height/2, center_width - face_with/2, center_y + face_height/2, paint); canvas.drawCircle(center_width, center_height, 10, paint); choseMap = createBitmap; image.setImageBitmap(choseMap); }