Skip to content

Commit

Permalink
add drawMarks to android BitMapImageFactory
Browse files Browse the repository at this point in the history
  • Loading branch information
sindhuvahinis committed Sep 9, 2024
1 parent f91a696 commit e083606
Showing 1 changed file with 33 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,29 @@ public void drawBoundingBoxes(DetectedObjects detections) {
oldBitmap.recycle();
}

/** {@inheritDoc} */
@Override
public void drawMarks(List<Point> points, int radius) {
Bitmap mutableBitmap = bitmap.copy(Bitmap.Config.ARGB_8888, true);
Canvas canvas = new Canvas(mutableBitmap);

// set the paint configure
Paint paint = new Paint();
paint.setStrokeWidth(2);
paint.setStyle(Paint.Style.FILL);
paint.setAntiAlias(true);

paint.setColor(darker(randomColor()));
for (Point point : points) {
int[][] star = createStar(point, radius);
drawPolygon(canvas, paint, star);
}

Bitmap oldBitmap = bitmap;
bitmap = mutableBitmap;
oldBitmap.recycle();
}

/** {@inheritDoc} */
@Override
public void drawJoints(Joints joints) {
Expand Down Expand Up @@ -395,5 +418,15 @@ private void drawMask(Bitmap image, Mask mask) {
Canvas canvas = new Canvas(image);
canvas.drawBitmap(maskedImage, x, y, null);
}

private void drawPolygon(Canvas canvas, Paint paint, int[][] polygon) {
android.graphics.Path polygonPath = new android.graphics.Path();
polygonPath.moveTo(polygon[0][0], polygonPath[1][0]);
for (int i = 1; i < polygon[0].length; i++) {
polygonPath.lineTo(polygon[0][i], polygon[1][i]);
}
polygonPath.close();
canvas.drawPath(polygonPath, paint);
}
}
}

0 comments on commit e083606

Please sign in to comment.