android通过for循环得到bitmap,不知道是不是异步的原因,uri每次都一样,如何解决,如何同步得到bitmap,我的uri也可能是网页url或者本地地址
for (ImagesEntity imagesEntity : imagesEntities) {
final String uri = imagesEntity.getImage();
BitmapUtils.getBitmap(getActivity(), uri, new BitmapUtils.LoadImageCallback() {
@Override
public void callback(Bitmap result) {
//getBitmap
}
});
}
public static void getBitmap(Context context, String uri, final LoadImageCallback callback) {
LogUtils.d("getBitmap: " + uri);
Glide.with(context)
.load(uri)
.asBitmap()
.into(new SimpleTarget<Bitmap>() {
@Override
public void onResourceReady(Bitmap bitmap, GlideAnimation anim) {
callback.callback(bitmap);
}
});
}
It can be placed in a thread. You can access the bitmap in this way and write the following method in the loop
uri is read from imagesEntity, uri is the same every time and has nothing to do with synchronization and asynchronousness
In addition, if you want to change this asynchronous callback to synchronous, just add get() after it, this method will wait until the result is returned