Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Hi guys I had the same trouble But i managed with something like this. I am sharing may be it will help.</p> <pre><code>public static LayerDrawable borderImageCircleBorder(Drawable draw, Activity activity) { int xCordinate = returnImageDrawableSize(draw); ShapeDrawable biggerCircle = new ShapeDrawable(new OvalShape()); biggerCircle.setIntrinsicHeight(xCordinate); biggerCircle.setIntrinsicWidth(xCordinate); biggerCircle.setBounds(new Rect(0, 0, xCordinate, xCordinate)); biggerCircle.getPaint().setColor(Color.WHITE); biggerCircle.setPadding(4, 4, 4, 4); ShapeDrawable smallerCircle = new ShapeDrawable(new OvalShape()); smallerCircle.setIntrinsicHeight(xCordinate); smallerCircle.setIntrinsicWidth(xCordinate); smallerCircle.setBounds(new Rect(0, 0, xCordinate, xCordinate)); smallerCircle.getPaint().setColor(Color.LTGRAY); smallerCircle.setPadding(2, 2, 2, 2); Drawable dd = getRoundedCornerBitmap(draw, activity); Drawable[] d = { smallerCircle, biggerCircle, dd }; LayerDrawable composite = new LayerDrawable(d); return composite; } public static int returnImageDrawableSize(Drawable image) { Bitmap original = ((BitmapDrawable) image).getBitmap(); Bitmap bitmap = original; //Log.i("original", "ht" + bitmap.getHeight() + ",wt=" + bitmap.getWidth()); int cropSizeWrtWidth, croppWrtHeight, xCoordinate, devideBy = 2; cropSizeWrtWidth = bitmap.getWidth() / devideBy - bitmap.getHeight() / devideBy; croppWrtHeight = bitmap.getHeight() / devideBy - bitmap.getWidth() / devideBy; xCoordinate = cropSizeWrtWidth &gt; 0 ? cropSizeWrtWidth : croppWrtHeight; float cordinates = bitmap.getWidth() / 2; // Find out ratio until we get a square bitmap while (bitmap.getHeight() &gt; bitmap.getWidth() &amp;&amp; xCoordinate + bitmap.getWidth() &gt; bitmap.getWidth()) { devideBy += 1; xCoordinate = bitmap.getHeight() / devideBy - bitmap.getWidth() / devideBy; if (xCoordinate + bitmap.getWidth() &lt;= bitmap.getWidth()) break; } return xCoordinate; } public static Drawable getRoundedCornerBitmap(Drawable image, Activity activity) { Bitmap original = ((BitmapDrawable) image).getBitmap(); ; Bitmap bitmap = original; //Log.i("original", "ht" + bitmap.getHeight() + ",wt=" + bitmap.getWidth()); int cropSizeWrtWidth, croppWrtHeight, xCoordinate, devideBy = 2; cropSizeWrtWidth = bitmap.getWidth() / devideBy - bitmap.getHeight() / devideBy; croppWrtHeight = bitmap.getHeight() / devideBy - bitmap.getWidth() / devideBy; xCoordinate = cropSizeWrtWidth &gt; 0 ? cropSizeWrtWidth : croppWrtHeight; float cordinates = bitmap.getWidth() / 2; // Find out ratio until we get a square bitmap while (bitmap.getHeight() &gt; bitmap.getWidth() &amp;&amp; xCoordinate + bitmap.getWidth() &gt; bitmap.getWidth()) { devideBy += 1; xCoordinate = bitmap.getHeight() / devideBy - bitmap.getWidth() / devideBy; if (xCoordinate + bitmap.getWidth() &lt;= bitmap.getWidth()) break; } if (bitmap.getWidth() &gt;= bitmap.getHeight()) { cordinates = bitmap.getHeight() / 2; bitmap = Bitmap.createBitmap(bitmap, xCoordinate, 0, bitmap.getHeight(), bitmap.getHeight()); } else { bitmap = Bitmap.createBitmap(bitmap, xCoordinate, 0, bitmap.getWidth(), bitmap.getWidth()); } //Log.i("bitmap after crop", "ht" + bitmap.getHeight() + ",wt=" + bitmap.getWidth()); Bitmap output = Bitmap.createBitmap(bitmap.getWidth(), bitmap.getHeight(), Config.ARGB_8888); int color = 0xff424242; Paint paint = new Paint(); paint.setColor(color); paint.setAntiAlias(true); Canvas canvas = new Canvas(output); canvas.drawARGB(0, 0, 0, 0); //Log.i("coordinates", "?????????" + cordinates); canvas.drawCircle(cordinates, cordinates, cordinates, paint); paint.setXfermode(new PorterDuffXfermode(Mode.SRC_IN)); Rect rect = new Rect(0, 0, bitmap.getWidth(), bitmap.getHeight()); canvas.drawBitmap(bitmap, rect, rect, paint); // output = // ShadowView.getCircleWhiteBorderBitmap(original,output,convertDpToPixel(12,activity)); Drawable d = new BitmapDrawable(activity.getResources(), output); return d; } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload