diff --git a/android/core/src/main/java/ai/djl/android/core/BitmapImageFactory.java b/android/core/src/main/java/ai/djl/android/core/BitmapImageFactory.java index 8142edfa5af..0c5ba2fcc49 100644 --- a/android/core/src/main/java/ai/djl/android/core/BitmapImageFactory.java +++ b/android/core/src/main/java/ai/djl/android/core/BitmapImageFactory.java @@ -283,6 +283,35 @@ public void drawBoundingBoxes(DetectedObjects detections, float opacity) { oldBitmap.recycle(); } + /** {@inheritDoc} */ + @Override + public void drawRectangle(Rectangle rect, int rgb, int thickness) { + Bitmap mutableBitmap = bitmap.copy(Bitmap.Config.ARGB_8888, true); + Canvas canvas = new Canvas(mutableBitmap); + int color = darker(rgb); + + // set the paint configure + Paint paint = new Paint(); + paint.setStyle(Paint.Style.STROKE); + paint.setStrokeWidth(thickness); + paint.setAntiAlias(true); + paint.setColor(color); + + int imageWidth = mutableBitmap.getWidth(); + int imageHeight = mutableBitmap.getHeight(); + int x = (int) (rect.getX() * imageWidth); + int y = (int) (rect.getY() * imageHeight); + canvas.drawRect( + x, + y, + x + (int) (rect.getWidth() * imageWidth), + y + (int) (rect.getHeight() * imageHeight), + paint); + Bitmap oldBitmap = bitmap; + bitmap = mutableBitmap; + oldBitmap.recycle(); + } + /** {@inheritDoc} */ @Override public void drawMarks(List points, int radius) { diff --git a/android/gradle.properties b/android/gradle.properties index c19a5830a76..c874913a9f1 100644 --- a/android/gradle.properties +++ b/android/gradle.properties @@ -17,5 +17,5 @@ org.gradle.jvmargs=-Xmx1536m android.useAndroidX=true # Automatically convert third-party libraries to use AndroidX android.enableJetifier=true -djl_version=0.30.0 -pytorch_version=2.4.0 +djl_version=0.31.0 +pytorch_version=2.5.1