2017-04-17 76 views
0

我想模糊這樣的形象,我需要將其設置爲RelativeLayout,它應該像下面給出這一形象創造模糊圖像:如何模糊圖像在Android和它設置爲相對佈局

Blur snapshot of my camera app when it changes the camera from front to rear

我使用了github的blurry庫,它使用這段代碼完成了我所有的工作,但我可以將其設置爲Imageview而不是RelativeLayout

Blurry.with(context).capture(view).into(imageView); 

所以,請給我解決方案。

+0

https://android-arsenal.com/details/1/5385 – Viven

+0

與相對佈局的模糊'到()'mehtod嘗試。例如。 (內容).radius(25).sampling(2).onto((ViewGroup)rootView);' –

+0

@PriyankPatel但它不能正常工作,它會在我啓動新活動時模糊不清。 – Pedo

回答

1

願這可以幫助你

自己保持高度和寬度

例子: -

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

    <ImageView 
     android:adjustViewBounds="true" 
     android:alpha="0.3" 
     android:layout_height="match_parent" 
     android:layout_width="match_parent" 
     android:scaleType="fitXY" 
     android:src="@drawable/abcd" /> 
</RelativeLayout> 
+0

這不是我需要的解決方案。它只是減少我的形象的亮度謝謝你。 – Pedo

0

嘗試RenderScriptFastBlur技術通過trickyandroid.com

​​

解釋
1

你可以用畢加索的BlurTransformation,並在自定義的目標加載圖像(在你的情況是RelativeLayout的)像

Picasso 
    .with(context) 
    .load(UsageExampleListViewAdapter.eatFoodyImages[0]) 
    .transform(new BlurTransformation(context)) 
    .into(new Target() { 
      @Override 
      public void onBitmapLoaded(Bitmap bitmap, Picasso.LoadedFrom from) { 

      } 

      @Override 
      public void onBitmapFailed(Drawable errorDrawable) { 

      } 

      @Override 
      public void onPrepareLoad(Drawable placeHolderDrawable) { 

      } 
    }); 
+0

謝謝,但這種方式只是模糊高達25半徑,我希望它高達50或100在我的問題我上傳的圖像有更多的模糊半徑,我想要的。請給我一個這樣做的方法。抱歉,因爲我的筆記本電腦沒有工作一個月,所以很遲纔回復。 – Pedo

1

它可以不使用任何庫文件來完成,只是創建圖層列表XML將文件放在可繪製的文件夾中並使用它。

對於模糊的效果,請在可繪製文件夾中創建blur.xml文件。

<?xml version="1.0" encoding="utf-8"?> 
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" > 
    <item android:drawable="@drawable/nature" /> <!-- change @drawable/nature with your desired image --> 
    <item> 
     <shape android:shape="rectangle"> 

<!-- You can use from 1% transparency to 100% transparency, according to your need,--> 
      <solid 
       android:color="#80FFFFFF"/> <!-- Here transparency level is 80%--> 
     </shape> 
    </item> 
    </layer-list> 

現在將它用作佈局文件中的背景圖像。

<RelativeLayout 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:background="@drawable/blur"> 

做,...

+0

它不工作,並感謝 – Pedo

+0

你有沒有正確實施它..我已經使用了相同的,並在我的項目中正常工作.. –

+0

好吧,我會再試一次 – Pedo

相關問題