Android Question ImageView corner round with border

megzz

Member
Licensed User
Longtime User
Hello,
I want to give to an imageview custom rounded corner with border with only java without using any library.
I tried using libraries but all of them makes the app slow because of their processing.
Is this possible ?
Thanks alot
 

megzz

Member
Licensed User
Longtime User
This forum is for B4A questions, not Java questions.
The code below is a mix of Java and B4A for making circle of image. But what Im searching for is a code for rounding only corners in custom radius.

B4X:
Sub GetRoundBitmap(Bmp As Bitmap) As Bitmap
javacircleround.InitializeContext
Return javacircleround.RunMethod("getRoundBitmap",Array(Bmp))
End Sub

#If Java
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Path;
import android.graphics.Rect;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.provider.MediaStore.Video.Thumbnails;
import android.media.ThumbnailUtils;

public static Bitmap getRoundBitmap(Bitmap scaleBitmapImage) {
  int targetWidth = 1000;
  int targetHeight = 1000;
  Bitmap targetBitmap = Bitmap.createBitmap(targetWidth, targetHeight,
    Bitmap.Config.ARGB_8888);

  Canvas canvas = new Canvas(targetBitmap);
  Path path = new Path();
  path.addCircle(((float) targetWidth - 1) / 2,
    ((float) targetHeight - 1) / 2,
    (Math.min(((float) targetWidth), ((float) targetHeight)) / 2),
    Path.Direction.CCW);

  canvas.clipPath(path);
  Bitmap sourceBitmap = scaleBitmapImage;
  canvas.drawBitmap(sourceBitmap, new Rect(0, 0, sourceBitmap.getWidth(),
    sourceBitmap.getHeight()), new Rect(0, 0, targetWidth,
    targetHeight), null);
  return targetBitmap;
}
public static Drawable getRoundDrawable(Drawable d){
  Bitmap b=getRoundBitmap(((BitmapDrawable) d).getBitmap());
  return new BitmapDrawable(b);
}
public Bitmap getThumbnail(String path){
        return ThumbnailUtils.createVideoThumbnail(path, Thumbnails.MINI_KIND);
    }
#End If
 
Upvote 0

Johan Schoeman

Expert
Licensed User
Longtime User
Upvote 0

Johan Schoeman

Expert
Licensed User
Longtime User
Upvote 0
Top