Glide.with(context)
.asBitmap()
.load(uri)
.into(new SimpleTarget<Bitmap>(Target.SIZE_ORIGINAL, Target.SIZE_ORIGINAL) {
@Override
public void onResourceReady(@NonNull Bitmap resource, @Nullable Transition<? super Bitmap> transition) {
int width = resource.getWidth();
int height = resource.getHeight();
// 设置想要的大小
int newWidth = ScreenUtils.getScreenWidth(context);
int newHeight = newWidth * height / width;
// 计算缩放比例
float scaleWidth = ((float) newWidth) / width;
float scaleHeight = ((float) newHeight) / height;
// 取得想要缩放的matrix参数
Matrix matrix = new Matrix();
matrix.postScale(scaleWidth, scaleHeight);
// 得到新的图片
resource = Bitmap.createBitmap(resource, 0, 0, width, height, matrix, true);
gifImageView.setImageBitmap(resource);
}
});
Glide.with(getApplicationContext())
.load(R.mipmap.app_center_add)
.diskCacheStrategy(DiskCacheStrategy.NONE)
.skipMemoryCache(true)
.listener(new RequestListener<Drawable>() {
@Override
public boolean onLoadFailed(@Nullable GlideException e, Object model, Target<Drawable> target, boolean isFirstResource) {
Toast.makeText(WelcomActivity.this, getString(R.string.nettip), Toast.LENGTH_SHORT).show();
// 本地sdk
return false;
}
@Override
public boolean onResourceReady(Drawable resource, Object model, Target<Drawable> target, DataSource dataSource, boolean isFirstResource) {
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
}
},2000);
return false;
}
}).into(welcomImage)
网友评论