Today, I mainly studied the use of Glide to get pictures Path and Bitmap. I believe it has troubled everyone for a long time. I also searched online for a long time, basically not. Later, I studied it and also referred to the following api documents. I summarized the following ways:
1. Get Bitmap:
1) After the image is downloaded and cached
-
Glide.with(mContext).load(url).asBitmap().into(new SimpleTarget<Bitmap>() {
-
@Override
-
public void onResourceReady(Bitmap resource, GlideAnimation<? super Bitmap> glideAnimation) {
-
image.setImageBitmap(resource);
-
}
-
});
Above is a simple method, below is a comprehensive method, can be perfectly controlled:
-
Glide.with(mContext).load(url).asBitmap().into(new Target<Bitmap>() {
-
@Override
-
public void onLoadStarted(Drawable placeholder) {
-
-
}
-
-
@Override
-
public void onLoadFailed(Exception e, Drawable errorDrawable) {
-
-
}
-
-
@Override
-
public void onResourceReady(Bitmap resource, GlideAnimation<? super Bitmap> glideAnimation) {
-
-
}
-
-
@Override
-
public void onLoadCleared(Drawable placeholder) {
-
-
}
-
-
@Override
-
public void getSize(SizeReadyCallback cb) {
-
-
}
-
-
@Override
-
public void setRequest(Request request) {
-
-
}
-
-
@Override
-
public Request getRequest() {
-
return null;
-
}
-
-
@Override
-
public void onStart() {
-
-
}
-
-
@Override
-
public void onStop() {
-
-
}
-
-
@Override
-
public void onDestroy() {
-
-
}
-
});
2) Obtain by url
-
Bitmap myBitmap = Glide.with(applicationContext)
-
.load(yourUrl)
-
.asBitmap()
-
.centerCrop()
-
.into(500, 500)
-
.get()
2. Get the image cache path
-
FutureTarget<File> future = Glide.with(mContext)
-
.load("url")
-
.downloadOnly(500, 500);
-
try {
-
File cacheFile = future.get();
-
String path = cacheFile.getAbsolutePath();
-
} catch (InterruptedException e) {
-
e.printStackTrace();
-
} catch (ExecutionException e) {
-
e.printStackTrace();
-
}
Note: This code needs to be executed in a thread, otherwise it will be saved.
From: http://blog.csdn .NET/qq_19711823/article/details/50856236