为了账号安全,请及时绑定邮箱和手机立即绑定

如何使用滑行将图像下载到位图中?

如何使用滑行将图像下载到位图中?

DIEA 2019-12-11 13:09:04
ImageView使用Glide 将网址下载到中非常容易:Glide   .with(context)   .load(getIntent().getData())   .placeholder(R.drawable.ic_loading)   .centerCrop()   .into(imageView);我想知道是否也可以下载到中Bitmap?我想下载到原始位图中,然后可以使用其他工具进行操作。我已经看过代码,看不到该怎么做。
查看完整描述

3 回答

?
jeck猫

TA贡献1909条经验 获得超7个赞

确保您使用的是最新版本


implementation 'com.github.bumptech.glide:glide:4.9.0'


科特林:


Glide.with(this)

        .asBitmap()

        .load(imagePath)

        .into(object : CustomTarget<Bitmap>(){

            override fun onResourceReady(resource: Bitmap, transition: Transition<in Bitmap>?) {

                imageView.setImageBitmap(resource)

            }

            override fun onLoadCleared(placeholder: Drawable?) {

                // this is called when imageView is cleared on lifecycle call or for

                // some other reason.

                // if you are referencing the bitmap somewhere else too other than this imageView

                // clear it here as you can no longer have the bitmap

            }

        })

位图大小:


如果要使用图像的原始大小,请使用上面的默认构造函数,否则可以将所需的大小传递给位图


into(object : CustomTarget<Bitmap>(1980, 1080)


Java:


Glide.with(this)

        .asBitmap()

        .load(path)

        .into(new CustomTarget<Bitmap>() {

            @Override

            public void onResourceReady(@NonNull Bitmap resource, @Nullable Transition<? super Bitmap> transition) {

                imageView.setImageBitmap(resource);

            }


            @Override

            public void onLoadCleared(@Nullable Drawable placeholder) {

            }

        });

旧答案:


随着 compile 'com.github.bumptech.glide:glide:4.8.0'以下


Glide.with(this)

        .asBitmap()

        .load(path)

        .into(new SimpleTarget<Bitmap>() {

            @Override

            public void onResourceReady(Bitmap resource, Transition<? super Bitmap> transition) {

                imageView.setImageBitmap(resource);

            }

        });

对于compile 'com.github.bumptech.glide:glide:3.7.0'及以下


Glide.with(this)

        .load(path)

        .asBitmap()

        .into(new SimpleTarget<Bitmap>() {

            @Override

            public void onResourceReady(Bitmap resource, GlideAnimation<? super Bitmap> glideAnimation) {

                imageView.setImageBitmap(resource);

            }

        });

现在您可能会看到一个警告 SimpleTarget is deprecated


原因:


弃用SimpleTarget的主要目的是警告您诱使您违反Glide的API合同的方式。具体来说,一旦清除SimpleTarget,它并不会迫使您停止使用已加载的任何资源,这可能导致崩溃和图形损坏。


将SimpleTarget仍然可以只要你确保你没有使用位图,一旦ImageView的清除使用。



查看完整回答
反对 回复 2019-12-12
  • 3 回答
  • 0 关注
  • 357 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信