我正在尝试使用Glide获取存储在SD卡上的图像的位图,但它对我不起作用。
Bitmap bitmapByGlide = Glide.with(this).load(imagePath).asBitmap().into(100, 100).get();
答案 0 :(得分:1)
您可以尝试这种方式:
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()就是这个技巧)
答案 1 :(得分:0)
试试这个。
Glide.with(this)
.load(url)
.asBitmap()
.into(new SimpleTarget<Bitmap>() {
@Override
public void onResourceReady(Bitmap resource, GlideAnimation<? super Bitmap> glideAnimation) {
}
});
答案 2 :(得分:0)
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
答案 3 :(得分:0)
试试这个:
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);