简体   繁体   中英

Fill a canvas with a transparent color in Android

Good Morning,

I have an ImageView that I initialized with #99aaaaaa color (it corresponds to 153,170, 170,170). after that I draw some lines with different colors. and Now I want to Fill my Canvas with the original color ( #99aaaaaa) .

The method myCanvas.drawColor(OriginalColor) fills the canvas with OriginalColor, but the lines still visible

    myPaint.setColor(OriginalColor);
    myPaint.setStyle(Paint.Style.FILL);
    myCanvas.drawRect(0, 0, 170, 170, myPaint); // my ImageView is  170X170

Also let lines visible.

Any help please, Thank You

as the canvas original color is semi transparent, then you draw something on it and draw another layer of semi transparent stuff, then its pretty obvious youll see the level-down-layer through the top transparent layer isnt it? another words, if you place a half transparent glass on your knees, ull still see the knees through it

Set the transfer mode as follows, before calling drawRec():

paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC));

Reset the painter afterwards, for further drawing:

paint.setXfermode(null);
paint.setColor(0xFFFFFFFF);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM