我正在尝试为我的位图图像添加阴影,但我无法弄清楚为什么它没有发生:
public static Bitmap pimpMyBitmap(Bitmap bitmap) { // Scales down, adds rounded edges and shadow
Bitmap output = Bitmap.createBitmap(360, 240, Config.ARGB_8888);
Canvas canvas = new Canvas(output);
final int color = 0xff424242;
final Paint paint = new Paint();
final Rect rect = new Rect(0, 0, bitmap.getWidth(), bitmap.getHeight());
final RectF rectF = new RectF(0, 0, 360, 240);
final float roundPx = 12;
paint.setShadowLayer(5.5f, 6.0f, 6.0f, 0xFF000000);
paint.setAntiAlias(true);
canvas.drawARGB(0, 0, 0, 0);
paint.setColor(color);
canvas.drawRoundRect(rectF, roundPx, roundPx, paint);
paint.setXfermode(new PorterDuffXfermode(Mode.SRC_IN));
canvas.drawBitmap(bitmap, rect, rectF, paint);
return output;
}
答案 0 :(得分:0)
如果您使用的是蜂窝及以上版本,请确保使用软件图层,因为从版本4.2开始,加速画布管道不支持setShadowLayer用于除文本以外的任何内容。
就在你的canvas.drawBitmap之前做这样的事情:
setLayerType(LAYER_TYPE_SOFTWARE, null);
欲了解更多信息,请阅读:http://developer.android.com/guide/topics/graphics/hardware-accel.html(向下滚动到“不支持的绘图操作”部分)