下列代码,请求网络图片转换为bitmap,然后保存到指定文件夹,微信,QQ分享,要求缩略图不大于32kb
压缩图片代码,使用了Glide来进行图片压缩处理
Glide.get(ShopDetailsActivity.this).clearMemory();
Log.e("分享图片地址链接分享", "分享图片地址:" + shopInfoEntity.getImgs().get(0).toString());
Glide.with(ShopDetailsActivity.this).load(shopInfoEntity.getImgs().get(0)).asBitmap().into(new SimpleTarget<Bitmap>() {
@Override
public void onResourceReady(Bitmap resource, GlideAnimation<? super Bitmap> glideAnimation) {
// //由于微信分享的图片要求在32k一下,所以要转换成缩略图
bitmap = Tool.createBitmapThumbnail(resource, false);
wxBitMap = bitmap;
// saveBitmap(bitmap);
// String sss = saveMyBitmap("fenxiang", bitmap);
saveBitmap(bitmap);
}
});
保存图片到本地
FileOutputStream out;
String bitmapName = "fenxiang.jpg";
File file;
String QQFilePath;
public void saveBitmap(Bitmap bmp) { try { // 获取SDCard指定目录下
String sdCardDir = Environment.getExternalStorageDirectory() + "/zupubao/";
File dirFile = new File(sdCardDir); //目录转化成文件夹
if (!dirFile.exists()) { //如果不存在,那就建立这个文件夹
dirFile.mkdirs();
} //文件夹有啦,就可以保存图片啦
File file = new File(sdCardDir, bitmapName);// 在SDcard的目录下创建图片文,以当前时间为其命名
out = new FileOutputStream(file);
bmp.compress(Bitmap.CompressFormat.JPEG, 100, out);
// System.out.println("_________保存到____sd______指定目录文件夹下____________________");
Log.e("saveBitMap", "saveBitmap: 图片保存到" + Environment.getExternalStorageDirectory() + "/zupubao/" + bitmapName);
QQFilePath = Environment.getExternalStorageDirectory() + "/zupubao/" + "fenxiang.jpg";
// showShare(QQFilePath);
showShare2();
out.flush();
out.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
// Toast.makeText(HahItemActivity.this,"保存已经至"+Environment.getExternalStorageDirectory()+"/CoolImage/"+"目录文件夹下", Toast.LENGTH_SHORT).show();
}
此博客作为笔记记录