开发者

How to draw a bitmap with transparency

How to draw a bitmap with a given 开发者_Go百科color set as transparent?

For example I want all white pixels to be transparent.


You need to set the Alpha value for the paint you're passing to the Bitmap.

http://developer.android.com/reference/android/graphics/Paint.html#setAlpha%28int%29

Values vary from 0-255

EDIT:

Paint p = new Paint();
//Set Blue Color
p.setColor(Color.WHITE);
//Set transparency roughly at 50%
p.setAlpha(125);


you need to check every pixel of image and change its color. you will get your answer in this Post


Another approach is drawing in trasparent color on your canvas (drawing holes). The bitmapu needs alpha channel.

    //Set transparent paint - you need all of these three
    Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);
    paint.setXfermode(new PorterDuffXfermode(Mode.SRC_OUT));
    paint.setColor(Color.TRANSPARENT);

    // Do you wanna soften?
    // Set paint transparency:
    // 0 = transparent ink, no visible effect
    // 255 = full ink, hole in the bitmap
    p.setAlpha(192);

    // Do you want some blur?
    // Set blur radius in pixel
    paint.setMaskFilter(new BlurMaskFilter(10, Blur.NORMAL));
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜