微信分享圆角图片有黑色部分

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/m0_37794706/article/details/78455639

近期做微信分享,分享时图片需要用app的logo做为分享图标,因为logo是一个圆角的图标,并且背景为透明色,所以导致分享后图片有黑色的部分


1.第一种解决方案就是直接让ui重新切图

2.直接用代码实现,给图片加白色的背景

在drawable下新建一个名为share_img_bg的文件,类型为layer-list


<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:drawable="@color/white" />
    <item android:drawable="@mipmap/ic_logo" />

</layer-list>


使用


Bitmap bitmap = CommomUtils.drawableToBitamp(context.getResources().getDrawable(R.drawable.shared_img_bg));

UMImage thumb = new UMImage(context, bitmap);//图片;



转换方法

/**
 * Drawable转换为Bitmap
 *
 * @param drawable
 * @return
 */
public static Bitmap drawableToBitamp(Drawable drawable) {
    int w = drawable.getIntrinsicWidth();
    int h = drawable.getIntrinsicHeight();
    Bitmap.Config config = drawable.getOpacity() != PixelFormat.OPAQUE ? Bitmap.Config.ARGB_8888
            : Bitmap.Config.RGB_565;
    Bitmap bitmap = Bitmap.createBitmap(w, h, config);
    // 注意,下面三行代码要用到,否在在View或者surfaceview里的canvas.drawBitmap会看不到图
    Canvas canvas = new Canvas(bitmap);
    drawable.setBounds(0, 0, w, h);
    drawable.draw(canvas);
    return bitmap;
}




如果对你有用 ,记得给妹子点个赞哦,么么哒



猜你喜欢

转载自blog.csdn.net/m0_37794706/article/details/78455639