Glide加载网络图片返回bitmap对象&RxTool缩放网络图片

首先我们有一个图片的URL:imageurl
要加载这个url的图片到一个Bitmap 对象bitmap

    private SimpleTarget target;
    String imageurl;

      target=new SimpleTarget() {
            @Override
            public void onResourceReady(@NonNull Bitmap bitmap, @Nullable Transition transition) {

//bitmap这里的bitmap就是我们需要的 通过后边Glide自动回调来赋值
//可以直接用来操作给imageview显示
                imageView.setImage(ImageSource.bitmap(bitmap));
            }
        };
        Glide
                .with( this )
                .asBitmap()// could be an issue!
                .load( imageurl )
                .into( target );

用Rxtool简单实现点击看大图,完整代码:
ShowImageActivity.class

package swust.yuqiaodan.tomatoapp.mvp.ui.activity;

import android.content.Context;
import android.graphics.Bitmap;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;

import com.bumptech.glide.Glide;
import com.bumptech.glide.request.target.SimpleTarget;
import com.bumptech.glide.request.target.Target;
import com.bumptech.glide.request.transition.Transition;
import com.jess.arms.base.BaseActivity;
import com.jess.arms.di.component.AppComponent;
import com.vondear.rxtool.RxTool;
import com.vondear.rxui.view.scaleimage.ImageSource;
import com.vondear.rxui.view.scaleimage.RxScaleImageView;

import java.util.concurrent.ExecutionException;

import butterknife.BindView;
import swust.yuqiaodan.tomatoapp.R;
import swust.yuqiaodan.tomatoapp.app.utils.RxUtils;

public class ShowImageActivity extends BaseActivity {
    RxScaleImageView imageView;
    private SimpleTarget target;
    String imageurl;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_show_image);
        RxTool.init(this);
        imageView = findViewById(R.id.Rx_imageView);
        imageurl=getIntent().getStringExtra("image");
        target=new SimpleTarget() {
            @Override
            public void onResourceReady(@NonNull Bitmap bitmap, @Nullable Transition transition) {
                imageView.setImage(ImageSource.bitmap(bitmap));
            }
        };
        Glide
                .with( this )
                .asBitmap()// could be an issue!
                .load( imageurl )
                .into( target );


        //imageView.setImage(ImageSource.bitmap(bitmap));
    }




    @Override
    public void setupActivityComponent(@NonNull AppComponent appComponent) {

    }

    @Override
    public int initView(@Nullable Bundle savedInstanceState) {
        return 0;
    }

    @Override
    public void initData(@Nullable Bundle savedInstanceState) {

    }
}

Layout文件:activity_show_image







你可能感兴趣的:(Glide加载网络图片返回bitmap对象&RxTool缩放网络图片)