微信分享透明背景圖片背景變黑

          微信圖片分享:分享給朋友正常,分享到朋友圈圖片就變黑了。查找資料後發現是因爲 

png的圖背景爲透明的原因引起的,將圖片的背景色設置上就可以了。

解決方法1: 把圖片背景換成全白色的(更換一張非圓角的圖片)

解決方法2:   代碼中對其更換背景顏色

//bitmap中的透明色用白色替換

    public static Bitmap changeColor(Bitmap bitmap) {
        if (bitmap == null) {
            return null;
        }
        int w = bitmap.getWidth();
        int h = bitmap.getHeight();
        int[] colorArray = new int[w * h];
        int n = 0;
        for (int i = 0; i < h; i++) {
            for (int j = 0; j < w; j++) {
                int color = getMixtureWhite(bitmap.getPixel(j, i));
                colorArray[n++] = color;
            }
        }
        return Bitmap.createBitmap(colorArray, w, h, 		    Bitmap.Config.ARGB_8888);
    }

    //獲取和白色混合顏色 
    private static int getMixtureWhite(int color) {
        int alpha = Color.alpha(color);
        int red = Color.red(color);
        int green = Color.green(color);
        int blue = Color.blue(color);
        return Color.rgb(getSingleMixtureWhite(red, alpha), getSingleMixtureWhite(green, alpha),
                getSingleMixtureWhite(blue, alpha));
    }

    // 獲取單色的混合值 
    private static int getSingleMixtureWhite(int color, int alpha) {
        int newColor = color * alpha / 255 + 255 - alpha;
        return newColor > 255 ? 255 : newColor;
    }
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章