2016-12-28 66 views
-1

我想不出我们怎么可以使用过滤器上的图像。如何在android中的图像上应用不同的颜色过滤器?

在这种情况下我想要的图像更暗(黑,40%的透明度,在图像的顶部层会给我我想要的结果)。然而,这将是(在未来)的帮助,如果我知道如何把一个层上任何颜色(有一些透明度)的图像,使其更具视觉与应用程序的其他用户界面元素兼容。

How it looks

现在的样子。

enter image description here

我怎么想它看起来在应用程序(上面的图片已经在Adobe Illustrator中进行编辑,但应用程序反复崩溃,如果我使用它,即使它的规模不是很大)

而且,我怀疑在android studio中一定有办法做到这一点,而不需要任何图像编辑软件。

纠正我,如果我错了;)

+0

图像有背景和src属性或使用ColorFilter –

+1

可能重复[在85%不透明度的Android黑色](http://stackoverflow.com/questions/6024867/android-black-color-at-85-opacity ) –

+0

不透明度看到这 - http://stackoverflow.com/a/17239853/7235539 ​​ –

回答

6

这是我做的,

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

色彩范围[00000000 -0xffffffff]

如果你不理解的模式,这可能帮助你

红 - 为0xffff0000

绿色-0xff00ff00

蓝 - 0xff0000ff

您的要求平均黑色0xff555555

改变颜色代码,只要你想>here

出把

enter image description here enter image description here enter image description here enter image description here


进一步:

setColorFilter PARAMS:(INT颜色, PorterDuff.Mode模式)

What does PorterDuff.Mode mean

+1

你的'here'链接是死 –

+1

没关系生病添加它感谢指着杜 –

+0

@Charuka非常感谢您抽出时间来显示输出。欣赏它! –

0

试试这个:

<RelativeLayout 
     android:layout_width="match_parent" 
     android:layout_height="match_parent"> 

     <ImageView 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:background="@android:color/black"/> 

     <ImageView 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:alpha=".5" 
      android:src="@drawable/your_naruto_img"/> 

    </RelativeLayout> 

当然你也可以据此改变android:alpha调整透明度 [0 - 1]。

希望这会有所帮助!

+0

不透明度和颜色过滤器是完全不同的事情! –

0

使用较暗的图像的任何在线工具生成9修补图像和使用,在您的应用程序9膜片。它会工作。

1

您可以使用对象的android:foreground属性设置在任何物体的颜色。这里我用了一个ImageView来显示图像,并android:foreground把过滤!

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/activity_main" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent"> 
<ImageView 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:src="@drawable/yourImage" 
    android:foreground="#60000000" /> 
</RelativeLayout> 

,如果你想这样做的布局,然后使用Android:背景属性,而不是android:src图像的来源。

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/activity_main" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:background="@drawable/yourImage" 
    android:foreground="#60000000"> 

</RelativeLayout> 
0

试试这个:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:background="@drawable/your_drawable"> 

    <ImageView 
     android:id="@+id/backImage" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:background="#66000000" 
     android:scaleType="fitXY"/> 
</RelativeLayout> 

可以设置该图像以为背景。使用imageview标签,并设置背景要设置transparent颜色。

+0

请不要通过回滚我们改进污损您的文章。 – FelixSFD

0

什么工作对我来说是

ImageView backgroundimage = FindViewById<ImageView>(Resource.Id.img_view); 
backgroundimage.SetColorFilter(Color.Argb(200,0,0,0), PorterDuff.Mode.Overlay); 

尝试了上述所有的答案后。 希望它可以帮助别人。

相关问题