2016-12-28 38 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); 

嘗試了上述所有的答案後。 希望它可以幫助別人。

相關問題