Note that there are some explanatory texts on larger screens.

plurals
  1. PODrawing an outer shadow when drawing an image
    text
    copied!<p>I currently create a rounded version of an image in my app by drawing to a canvas. I would like to draw a faint outershadow around the image, but I cant quite get it right. I have 2 questions: 1. How can I draw an outer shadow (I can only seem to draw a shadow with a x or y offset) 2. How can I draw the shadow so that it does not have the artifacts shown in the attached image. Code:</p> <pre><code>![public Bitmap getRoundedCornerBitmap(Bitmap bitmap, float cornerRadius) { Bitmap output = Bitmap.createBitmap(bitmap.getWidth()+6, bitmap.getHeight() +6, Config.ARGB_8888); Canvas canvas = new Canvas(output); final int color = 0xff424242; int shadowRadius = getDipsFromPixel(3); final Rect imageRect = new Rect(shadowRadius, shadowRadius, bitmap.getWidth(), bitmap.getHeight()); final RectF rectF = new RectF(imageRect); // This does not achieve the desired effect Paint shadowPaint = new Paint(); shadowPaint.setAntiAlias(true); shadowPaint.setColor(Color.BLACK); shadowPaint.setShadowLayer((float)shadowRadius, 2.0f, 2.0f,Color.BLACK); canvas.drawOval(rectF, shadowPaint); canvas.drawARGB(0, 0, 0, 0); final Paint paint = new Paint(); paint.setAntiAlias(true); paint.setColor(color); canvas.drawRoundRect(rectF, cornerRadius, cornerRadius, paint); paint.setXfermode(new PorterDuffXfermode(Mode.SRC_IN)); canvas.drawBitmap(bitmap, imageRect, imageRect, paint); return output; }][1] </code></pre> <p><img src="https://i.stack.imgur.com/d7DV6.png" alt="http://i.stack.imgur.com/d7DV6.png"></p> <p>This is an example of the effect I am trying to achieve: <img src="https://i.stack.imgur.com/FFb0R.png" alt="enter image description here"></p>
 

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