下载网络图片
| 12
 3
 4
 5
 6
 7
 8
 9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 
 | 
 Bitmap bitmap = Glide.with(applicationContext)
 .load(url)
 .asBitmap()
 .into(Target.SIZE_ORIGINAL, Target.SIZE_ORIGINAL)
 .get();
 
 Bitmap bitmap = BitmapFactory.decodeStream(new URL(url).openStream());
 
 
 
 
 
 
 File imgDir = new File(getDiskCacheDir(applicationContext), "image_caches");
 if (!imgDir.exists()) {
 imgDir.mkdirs();
 }
 File imgFile = new File(imgDir, fileName);
 fileOutputStream = new FileOutputStream(imgFile);
 Bitmap.CompressFormat compressFormat = Bitmap.CompressFormat.PNG;
 bitmap.compress(compressFormat, 100, fileOutputStream);
 fileOutputStream.flush();
 
 
 | 
Glide预加载图片
| 12
 3
 4
 5
 6
 7
 8
 9
 10
 11
 12
 13
 14
 15
 16
 
 | public static void preloadImage(Context context, AdZone adZone) {for (AdZone.Item item : adZone.getItems()) {
 new Thread(() -> {
 try {
 Glide.with(context.getApplicationContext())
 .load(item.getPic())
 .downloadOnly(Target.SIZE_ORIGINAL, Target.SIZE_ORIGINAL)
 .get();
 } catch (InterruptedException e) {
 e.printStackTrace();
 } catch (ExecutionException e) {
 e.printStackTrace();
 }
 }).start();
 }
 }
 
 | 
| 12
 3
 4
 5
 6
 7
 8
 9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 
 | Glide.with(getApplicationContext()).load(pic)
 .diskCacheStrategy(DiskCacheStrategy.ALL)
 .into(new GlideDrawableImageViewTarget(ivWelcome) {
 @Override
 protected void setResource(GlideDrawable resource) {
 
 super.setResource(resource);
 
 ivWelcome.setOnClickListener(v -> {
 sendAdZoneItemBroadcast(item);
 });
 ivWelcome.setVisibility(View.VISIBLE);
 
 
 toCountDown();
 }
 
 @Override
 public void onLoadFailed(Exception e, Drawable errorDrawable) {
 super.onLoadFailed(e, errorDrawable);
 }
 });
 
 |