微信分享图片变黑
2016-04-16 16:30
579 查看
最近做微信分享遇到图片分享的问题:分享给朋友正常,分享到朋友圈图片就变黑了。查找资料后发现是因为
png的图背景为透明的原因引起的,将图片的背景色设置上就可以了。
png的图背景为透明的原因引起的,将图片的背景色设置上就可以了。
/** * bitmap中的透明色用白色替换 * * @param bitmap * @return */ 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); } /** * 获取和白色混合颜色 * * @return */ 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)); } /** * 获取单色的混合值 * * @param color * @param alpha * @return */ private static int getSingleMixtureWhite(int color, int alpha) { int newColor = color * alpha / 255 + 255 - alpha; return newColor > 255 ? 255 : newColor; }
相关文章推荐
- 微信红包系统设计分享 | 如何扛住100亿次请求
- 微信开发
- 人人,金山西山居,腾讯互娱,微信,网易游戏offer及面经
- VS 星期作业 if else的应用 做一个受不受异性欢迎的小程序
- 高仿微信新消息提示音功能
- 使用cookie实现记录浏览商品的过程并能够清空浏览记录(简单的小程序不涉及到数据库的调取)
- 使用JSSDK集成微信分享遇到的一些坑
- 【转】微信扫描二维码登录网页是什么原理?
- 微信抽奖类游戏设计
- Django:之中间件、微信接口和单元测试
- 微信公众号如何取名好?
- 微信公众号欢迎语怎么设置才有吸引力?
- ***微信LBS地理位置开发+百度地图API(地理位置和坐标转换)
- showPopupWindow 类似微信+
- Android学习之Android 5.0分享动画实现微信点击全屏效果
- 微信移动客户端内部浏览器分享到朋友圈,QQ空间代码
- 微信开放平台开发(3) 移动应用微信登录
- 微信开放平台开发(3) 移动应用微信登录
- 微信开放平台开发(3) 移动应用微信登录
- 微信硬件蓝牙开发各种坑不完全开发指南