使用Android Paint类中的PorterDuffXfermode更改位图上的变亮/变暗强度 [英] changing the intensity of lighten/darken on bitmaps using PorterDuffXfermode in the Android Paint class

查看:150
本文介绍了使用Android Paint类中的PorterDuffXfermode更改位图上的变亮/变暗强度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好吧,我的原始问题已经改变。

  DayToNight.setXfermode(new PorterDuffXfermode(Mode.DST_IN))如何改变这种情况的强度? ; 

在我的梦幻世界里,它会像这样工作

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

10是强度级别。



< hr>

一个例子是如果我有一个闪烁的蜡烛,当蜡烛燃烧得很亮时我想要我画到屏幕上的位图保持原始的颜色和亮度,当它闪烁我希望位图几乎变黑,并且我想在光线变暗时将位图变暗。



我有方程式,定时器和所有计算出来的,只是没有如何实际应用它来改变颜色/亮度。
也许烧图像是我在找什么?
我只是想改变亮度lol。



我觉得使用paint.setShader可能是一个解决方案,但这方面的信息相当有限我能找到的。任何帮助,将不胜感激。



编辑:要清楚,我正在寻找一种方法来减轻/加深位图,因为我将它们绘制到画布上

解决方案

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


  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

这篇关于使用Android Paint类中的PorterDuffXfermode更改位图上的变亮/变暗强度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆