使用 Glide 从 SD 卡获取位图 android
get Bitmap from SD card using Glide android
我正在尝试使用 Glide 获取存储在 SD 卡上的图像的位图,但它对我不起作用。
Bitmap bitmapByGlide = Glide.with(this).load(imagePath).asBitmap().into(100, 100).get();
试试这个。
Glide.with(this)
.load(url)
.asBitmap()
.into(new SimpleTarget<Bitmap>() {
@Override
public void onResourceReady(Bitmap resource, GlideAnimation<? super Bitmap> glideAnimation) {
}
});
private SimpleTarget target = new SimpleTarget<Bitmap>() {
@Override
public void onResourceReady(Bitmap bitmap, GlideAnimation glideAnimation) {
// do something with the bitmap
// for demonstration purposes, let's just set it to an ImageView
imageView1.setImageBitmap( bitmap );
}
};
private void loadImageSimpleTarget() {
Glide
.with( context ) // could be an issue!
.load( eatFoodyImages[0] )
.asBitmap()
.into( target );
}
来源:https://futurestud.io/tutorials/glide-callbacks-simpletarget-and-viewtarget-for-custom-view-classes
你可以这样试试:
Glide.with(this)
.load(Uri.fromFile(new File(url)))
.asBitmap()
.into(new SimpleTarget<Bitmap>() {
@Override
public void onResourceReady(Bitmap resource, GlideAnimation<? super Bitmap> glideAnimation) {
bitmapByGlide = resource;
}
});
(使用 Uri.formFile() 是这个技巧)
试试这个:
File b = new File(Environment.getExternalStorageDirectory(), "DCIM/Camera/IMG_20150828_174009.jpg");
和
Glide.with(MainActivity.this).load(b).error(R.drawable.empty_pic).placeholder(R.drawable.empty_pic).into(image2);
我正在尝试使用 Glide 获取存储在 SD 卡上的图像的位图,但它对我不起作用。
Bitmap bitmapByGlide = Glide.with(this).load(imagePath).asBitmap().into(100, 100).get();
试试这个。
Glide.with(this)
.load(url)
.asBitmap()
.into(new SimpleTarget<Bitmap>() {
@Override
public void onResourceReady(Bitmap resource, GlideAnimation<? super Bitmap> glideAnimation) {
}
});
private SimpleTarget target = new SimpleTarget<Bitmap>() {
@Override
public void onResourceReady(Bitmap bitmap, GlideAnimation glideAnimation) {
// do something with the bitmap
// for demonstration purposes, let's just set it to an ImageView
imageView1.setImageBitmap( bitmap );
}
};
private void loadImageSimpleTarget() {
Glide
.with( context ) // could be an issue!
.load( eatFoodyImages[0] )
.asBitmap()
.into( target );
}
来源:https://futurestud.io/tutorials/glide-callbacks-simpletarget-and-viewtarget-for-custom-view-classes
你可以这样试试:
Glide.with(this)
.load(Uri.fromFile(new File(url)))
.asBitmap()
.into(new SimpleTarget<Bitmap>() {
@Override
public void onResourceReady(Bitmap resource, GlideAnimation<? super Bitmap> glideAnimation) {
bitmapByGlide = resource;
}
});
(使用 Uri.formFile() 是这个技巧)
试试这个:
File b = new File(Environment.getExternalStorageDirectory(), "DCIM/Camera/IMG_20150828_174009.jpg");
和
Glide.with(MainActivity.this).load(b).error(R.drawable.empty_pic).placeholder(R.drawable.empty_pic).into(image2);