3 回答

TA貢獻1909條經(jīng)驗 獲得超7個贊
確保您使用的是最新版本
implementation 'com.github.bumptech.glide:glide:4.9.0'
科特林:
Glide.with(this)
.asBitmap()
.load(imagePath)
.into(object : CustomTarget<Bitmap>(){
override fun onResourceReady(resource: Bitmap, transition: Transition<in Bitmap>?) {
imageView.setImageBitmap(resource)
}
override fun onLoadCleared(placeholder: Drawable?) {
// this is called when imageView is cleared on lifecycle call or for
// some other reason.
// if you are referencing the bitmap somewhere else too other than this imageView
// clear it here as you can no longer have the bitmap
}
})
位圖大?。?/p>
如果要使用圖像的原始大小,請使用上面的默認構(gòu)造函數(shù),否則可以將所需的大小傳遞給位圖
into(object : CustomTarget<Bitmap>(1980, 1080)
Java:
Glide.with(this)
.asBitmap()
.load(path)
.into(new CustomTarget<Bitmap>() {
@Override
public void onResourceReady(@NonNull Bitmap resource, @Nullable Transition<? super Bitmap> transition) {
imageView.setImageBitmap(resource);
}
@Override
public void onLoadCleared(@Nullable Drawable placeholder) {
}
});
舊答案:
隨著 compile 'com.github.bumptech.glide:glide:4.8.0'以下
Glide.with(this)
.asBitmap()
.load(path)
.into(new SimpleTarget<Bitmap>() {
@Override
public void onResourceReady(Bitmap resource, Transition<? super Bitmap> transition) {
imageView.setImageBitmap(resource);
}
});
對于compile 'com.github.bumptech.glide:glide:3.7.0'及以下
Glide.with(this)
.load(path)
.asBitmap()
.into(new SimpleTarget<Bitmap>() {
@Override
public void onResourceReady(Bitmap resource, GlideAnimation<? super Bitmap> glideAnimation) {
imageView.setImageBitmap(resource);
}
});
現(xiàn)在您可能會看到一個警告 SimpleTarget is deprecated
原因:
棄用SimpleTarget的主要目的是警告您誘使您違反Glide的API合同的方式。具體來說,一旦清除SimpleTarget,它并不會迫使您停止使用已加載的任何資源,這可能導致崩潰和圖形損壞。
將SimpleTarget仍然可以只要你確保你沒有使用位圖,一旦ImageView的清除使用。
- 3 回答
- 0 關(guān)注
- 404 瀏覽
添加回答
舉報