有没有一种简单的方法可以用 Glide 显示带有框架的图像?
Is there a simple way to show an image with a frame with Glide?
我想在我使用 Glide 加载的图像周围添加一个框架。我的图像没有固定大小,因此添加框架作为背景不起作用。
有制作相框的简单方法吗?
是的,有办法。
int myWidth = 512;
int myHeight = 512;
int borderSize=20;
Glide.with(yourApplicationContext))
.load(youUrl)
.asBitmap()
.into(new SimpleTarget<Bitmap>(myWidth, myHeight) {
@Override
public void onResourceReady(Bitmap bitmap, GlideAnimation anim) {
Bitmap bmpWithBorder = Bitmap.createBitmap(bitmap.getWidth() + borderSize * 2, bitmap.getHeight() + borderSize * 2, bitmap.getConfig());
Canvas canvas = new Canvas(bmpWithBorder);
canvas.drawColor(Color.WHITE);
canvas.drawBitmap(bitmap, borderSize, borderSize, null);
//Now you can use bmpWithBorder on ImageView you want
}
};
我想在我使用 Glide 加载的图像周围添加一个框架。我的图像没有固定大小,因此添加框架作为背景不起作用。 有制作相框的简单方法吗?
是的,有办法。
int myWidth = 512;
int myHeight = 512;
int borderSize=20;
Glide.with(yourApplicationContext))
.load(youUrl)
.asBitmap()
.into(new SimpleTarget<Bitmap>(myWidth, myHeight) {
@Override
public void onResourceReady(Bitmap bitmap, GlideAnimation anim) {
Bitmap bmpWithBorder = Bitmap.createBitmap(bitmap.getWidth() + borderSize * 2, bitmap.getHeight() + borderSize * 2, bitmap.getConfig());
Canvas canvas = new Canvas(bmpWithBorder);
canvas.drawColor(Color.WHITE);
canvas.drawBitmap(bitmap, borderSize, borderSize, null);
//Now you can use bmpWithBorder on ImageView you want
}
};