且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

使用Android Paint类中的PorterDuffXfermode更改位图上的变亮/变暗强度

更新时间:2023-01-28 08:06:09

这两种方法可以解决您的问题:


  1. 在位图后面放置一个黑色矩形,并设置位图的
    不透明度。

  2. 在绘制位图时,在Paint上使用ColorFilter。使位图变暗使用半透明黑色


Ok my orignal question has changed. How do i change the intensity of how something like this is effected?

    DayToNight.setXfermode(new PorterDuffXfermode(Mode.DST_IN));

in my dream world it would have worked like this

    DayToNight.setXfermode(new PorterDuffXfermode(Mode.DST_IN(10)));

the 10 being a level of intensity.


An example would be if I had a flickering candle, when the candle burns bright I want the bitmaps I am drawing to the screen to retain their origanol color and brightness, when it flickers I want the bitmaps to be almost blacked out, and I want to darken the Bitmaps as the light dims.

I have equations, timers and all that figured out, just not how to actually apply it to change the color/brightness. Maybe burning the images is what im looking for? I just want to change the lightness lol.

I feel like using paint.setShader might be a solution, but the information in this area is pretty limited from what i have been able to find. Any help would be appreciated.

edit: to be crystal clear, i am looking for a way to lighten/darken bitmaps as I draw them to the canvas

These two approaches may solve your problem:

  1. Put a dark rectangle behind your bitmap and set the Bitmap's opacity.

  2. Use ColorFilter on your Paint when you draw the bitmap. To darken your bitmap use a semi-transparent black color