how to draw a Bitmap to a Canvas with a variable alpha

Posted by steelbytes on Stack Overflow See other posts from Stack Overflow or by steelbytes
Published on 2010-05-18T07:27:40Z Indexed on 2010/05/18 7:30 UTC
Read the original article Hit count: 201

Filed under:
|
|

Hi, I'm trying to draw a Bitmap to a Canvas with a variable amount of alpha. But I only get nothing (when alpha<255) or the 'full' bitmap (when alpha==255).

Have also tried loading as a Drawable, and using drawable.setAlpha, but that gave the same result.

my init

BitmapFactory.Options opts = new BitmapFactory.Options();
opts.inScaled = false;
opts.inSampleSize = 1;
Bitmap img = BitmapFactory.decodeResource(getResources(),R.drawable.sample,opts);

my onDraw()

Paint p = new Paint(Paint.ANTI_ALIAS_FLAG|Paint.FILTER_BITMAP_FLAG);
p.setColor((alpha<<24)+0xffffff);  // alpha in range 0..255
canvas.drawBitmap(img, null, imgRect, p);

© Stack Overflow or respective owner

Related posts about android

Related posts about canvas