直接獲取File / Bitmap / File / Gif
public void downloadImage() {
new Thread(new Runnable() {
@Override
public void run() {
try {
String url = "http://www.guolin.tech/book.png";
final Context context = getApplicationContext();
FutureTarget<File> target = Glide.with(context)
.asFile()
.load(url)
.submit();
final File imageFile = target.get();
runOnUiThread(new Runnable() {
@Override
public void run() {
Toast.makeText(context, imageFile.getPath(), Toast.LENGTH_LONG).show();
}
});
} catch (Exception e) {
e.printStackTrace();
}
}
}).start();
}
URL轉(zhuǎn)Drawable
SimpleTarget<Drawable> simpleTarget = new SimpleTarget<Drawable>() {
@Override
public void onResourceReady(Drawable resource, Transition<? super Drawable> transition) {
imageView.setImageDrawable(resource);
}
};
public void loadImage(View view) {
Glide.with(this)
.load("http://guolin.tech/book.png")
.into(simpleTarget);
}
4.0以下的怎么獲取bitmap ??
Bitmap myBitmap = Glide.with(applicationContext)
.load(yourUrl)
.asBitmap()
.centerCrop()
.into(Target.SIZE_ORIGINAL,Target.SIZE_ORIGINAL)
.get() ;