如何在android中的图像上应用不同的颜色过滤器? [英] How to apply different colour filters on an image in android?

查看:180
本文介绍了如何在android中的图像上应用不同的颜色过滤器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我无法弄清楚如何在图像上应用滤镜。



在这种情况下,我希望图像更暗(黑色,40%透明度,图像顶部的图层会给我想要的结果。但是,如果我知道如何将图层放在任何颜色的图像上(具有一定的透明度)以使其在视觉上与应用程序的其他UI元素更加兼容,那将是有用的(将来)。





现在看起来如何。





我希望它在应用上看起来如何(上面的图像已在Adobe中编辑过)插图画家,但如果我使用它,即使它的大小不大,应用程序反复崩溃)



此外,我怀疑必须有一种方法在没有需要任何图像编辑软件。



如果我错了,请纠正我;)

解决方案

这是我做什么,

  imageView =(ImageView)findViewById(R.id.image_view); 
imageView.getDrawable()。setColorFilter(0x76ffffff,PorterDuff.Mode.MULTIPLY);

颜色范围[0x00000000 -0xffffffff]



如果您不理解这种模式可能会对您有所帮助


红色 - 0xffff0000



green -0xff00ff00



blue - 0xff0000ff



您的请求平均黑色0xff555555


根据需要更改颜色代码>







更多信息:



setColorFilter params:(int color,
PorterDuff.Mode mode)



PorterDuff.Mode是什么意思


I can't figure out how can we apply filters over an image.

In this case I want the image to be darker (black, 40% transparency, layer on top of the image would give me the result I want). However, it will be helpful (in future) if I know how to put a layer over an image of any color (with some transparency) to make it more visually compatible with the other UI elements of the app.

How it looks now.

How I want it to look on the app (the above image has been edited in Adobe illustrator but the app repeatedly crashes if I use it even though its size is not large)

Also, I suspect there must be a way to do this in android studio without the need of any image editing software.

Correct me if I am wrong ;)

解决方案

This is what i do ,

 imageView =(ImageView) findViewById(R.id.image_view) ;
 imageView.getDrawable().setColorFilter(0x76ffffff, PorterDuff.Mode.MULTIPLY );

color range [0x00000000 -0xffffffff]

If you don't understand the pattern this might help you

Red - 0xffff0000

green -0xff00ff00

blue - 0xff0000ff

your request average black color 0xff555555

change color codes as you want > here

out put


Further more :

setColorFilter params : (int color, PorterDuff.Mode mode)

What does PorterDuff.Mode mean

这篇关于如何在android中的图像上应用不同的颜色过滤器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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