Bitmap 生成微信分享图标

时间:2015-02-15 12:00:20   收藏:0   阅读:349

android开发调用微信分享接口在设置分享图标时,必须对原图进行压缩处理,否则分享出来的图标会不清晰。据本人了解,微信分享的图标大小是132px*132px的。

下面给出方法

 1 public static Bitmap crateWeixinShareIcon(Bitmap bmp, int target) {
 2         int width = bmp.getWidth();
 3         int height = bmp.getHeight();
 4 
 5         if (width < target || height < target)
 6             return bmp;
 7 
 8         Bitmap bmpnew;
 9         if (width > height) {
10             bmpnew = Bitmap.createBitmap(bmp, (width - height) / 2, 0, height,
11                     height);
12         } else {
13             bmpnew = Bitmap.createBitmap(bmp, 0, (height - width) / 2, width,
14                     width);
15         }
16 
17         Bitmap result = Bitmap.createScaledBitmap(bmpnew, target, target, true);
18         bmpnew.recycle();
19         return result;
20     }

调用

1 Bitmap shareIcon = Common.crateWeixinShareIcon(bmp, 132);

 

评论(0
© 2014 mamicode.com 版权所有 京ICP备13008772号-2  联系我们:gaon5@hotmail.com
迷上了代码!