2019独角兽企业重金招聘Python工程师标准>>>
public class ImgUtils {public static void saveImageToGallery(Context context, Bitmap bmp) {final String[] items = new String[] { "保存图片"};//图片转成Bitmap数组final Bitmap[] bitmap = new Bitmap[1];bitmap[0] = bmp;// Glide.with(context).load(url).asBitmap().into(new SimpleTarget<Bitmap>() {
// @Override
// public void onResourceReady(@NonNull Bitmap resource, @Nullable Transition<? super Bitmap> transition) {
// bitmap[0] = resource;
// }
// });// 首先保存图片 创建文件夹File appDir = new File(Environment.getExternalStorageDirectory(), "shy");if (!appDir.exists()) {appDir.mkdir();}//图片文件名称String fileName = "shy_"+System.currentTimeMillis() + ".jpg";File file = new File(appDir, fileName);try {FileOutputStream fos = new FileOutputStream(file);bmp.compress(Bitmap.CompressFormat.JPEG, 100, fos);fos.flush();fos.close();} catch (Exception e) {e.printStackTrace();}// 其次把文件插入到系统图库String path = file.getAbsolutePath();try {MediaStore.Images.Media.insertImage(context.getContentResolver(), path, fileName, null);} catch (FileNotFoundException e) {e.printStackTrace();}// 最后通知图库更新Intent intent = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE);Uri uri = Uri.fromFile(file);intent.setData(uri);context.sendBroadcast(intent);new ToastUtils(context).showToast("保存成功");}}