我想从url获取位图然后想将其转换为字节数组以将其存储到sqlite中,我使用滑动来获取url这里的位图是我的代码
Bitmap temp = null;
Bitmap temp2 = null;
try {
temp = Glide.with(this)
.load(urlNavHeaderBg)
.asBitmap()
.into(-1, -1)
.get();
temp2 = Glide.with(this)
.load(profile_pic_url)
.asBitmap()
.into(-1, -1)
.get();
} catch (InterruptedException e) {
e.printStackTrace();
} catch (ExecutionException e) {
e.printStackTrace();
}
如果有人有更好的想法获取位图并将其转换为字节数组,那么随时建议
答案 0 :(得分:0)
试试这个
Glide.with(this)
.load(urlNavHeaderBg)
.asBitmap()
.placeholder(R.drawable.place_holder_image)
.error(R.drawable.place_holder_image)
.into(new SimpleTarget<Bitmap>() {
@Override
public void onResourceReady(final Bitmap resource, GlideAnimation<? super Bitmap> glideAnimation) {
Bitmap bimtapImage=resource;
//Convert this bimtapImage to byte array
}
@Override
public void onLoadFailed(Exception e, Drawable errorDrawable) {
super.onLoadFailed(e, errorDrawable);
}
});