[英]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(Uri.fromFile(new File(url)))
.asBitmap()
.into(new SimpleTarget<Bitmap>() {
@Override
public void onResourceReady(Bitmap resource, GlideAnimation<? super Bitmap> glideAnimation) {
bitmapByGlide = resource;
}
});
(使用Uri.formFile()是技巧)
尝试这个。
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
尝试这个:
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);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.