android如何在画布上绘制半透明的位图

时间:2011-09-15 23:17:23

标签: android bitmap transparency

我试图修改一个Paint变量,但是一直不成功 - 我怎样才能让位图显示为“半透明”?

2 个答案:

答案 0 :(得分:42)

canvas.drawColor(Color.WHITE);   
BitmapDrawable bd = (BitmapDrawable) getResources().getDrawable(R.drawable.loading);    
Bitmap bm = bd.getBitmap();    
Paint paint = new Paint();    
paint.setAlpha(60);                             //you can set your transparent value here    
canvas.drawBitmap(bm, 0, 0, paint);

答案 1 :(得分:0)

Paint p = new Paint();
p.setAlpha(70);

Bitmap image = BitmapFactory.decodeResource(getResources(), R.drawable.wallpaper);
canvas.drawBitmap(image, xPosition, yPosition, p);