changing the intensity of lighten/darken on bitmaps using PorterDuffXfermode in the Android Paint class

主宰稳场 提交于 2019-12-21 20:34:12

问题


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


回答1:


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




回答2:


Hey I have used a kind of trick to remove the black line.In my erase button, I have set the color to white, instead of using XferMode.. It works and looks good..

if(erase){
paintColor = Color.parseColor(newColor);
drawPaint.setColor(paintColor);
}


来源:https://stackoverflow.com/questions/11174583/changing-the-intensity-of-lighten-darken-on-bitmaps-using-porterduffxfermode-in

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!