android如何同步得到bitmap
PHPz
PHPz 2017-04-17 17:24:41
0
2
484

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);
                    }
                });
    }
PHPz
PHPz

学习是最好的投资!

reply all(2)
洪涛

It can be placed in a thread. You can access the bitmap in this way and write the following method in the loop

 bitmap = Glide.with(context)
                .load(getGlideUrl(url))
                .asBitmap()
                .diskCacheStrategy(DiskCacheStrategy.ALL)
                .into(Target.SIZE_ORIGINAL, Target.SIZE_ORIGINAL)
                .get();
黄舟

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

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template