簡體   English   中英

模糊圖像位圖並將其設置為背景

[英]Blur Image bitmap and set it as background

我一直在嘗試模糊圖像視圖並將整個布局的背景設置為模糊的位圖無濟於事。 基本上我試圖實現的內容顯示在這些圖片中,它們只模糊 imageView 並將擴展的模糊圖像設置為布局背景。

在此處輸入圖片說明

在此處輸入圖片說明

int color = getDominantColor(bitmap); //get dominant color of the bitmap

 //create gradient
                GradientDrawable gradient = new GradientDrawable(
                        GradientDrawable.Orientation.TOP_BOTTOM,
                        new int[] {0xf5f5f5,color});
                gradient.setCornerRadius(0f);

                //setbackground of the relativelayout
                rl.setBackground(gradient);//rl is relative layout





  //getting dominant color of bitmap
public static int getDominantColor(Bitmap bitmap) {
    Bitmap newBitmap = Bitmap.createScaledBitmap(bitmap, 1, 1, true);
    final int color = newBitmap.getPixel(0, 0);
    newBitmap.recycle();
    return color;
}

我不希望 tp 將背景設置為漸變,而是作為該圖像位圖的模糊結果,就像我包含的圖像一樣。

有很多選擇:

  1. 您可以放大然后縮小位圖。 這樣做是減少產生模糊效果之類的圖片數量。 如果您想這樣做,請參見此處: Android SDK 的快速位圖模糊 但是,它的內存效率不是很高,如果它像這樣工作,您可能需要更改您的實現。
  2. 使用預制庫。 有許多庫,有些比其他庫更好,允許您模糊位圖。 制作這些庫的人已經在減少內存使用和更好的兼容性方面做了艱苦的工作。 這里還有一個例子: Fast Bitmap Blur For Android SDK

注意:我沒有發布任何代碼,因為解決方案的一部分是庫或自定義類。

希望能幫助到你。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM