Glide assert 出错:java.lang.IllegalArgumentException: 你必须在主线程上调用这个方法

getting error with Glide assert: java.lang.IllegalArgumentException: You must call this method on the main thread

我想从 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();
    }

如果有人对获取位图并将其转换为字节数组有更好的想法,请随时提出建议

试试这个

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