首先我们有一个图片的URL:imageurl
要加载这个url的图片到一个Bitmap 对象bitmap
private SimpleTarget target;
String imageurl;
target=new SimpleTarget<Bitmap>() {
@Override
public void onResourceReady(@NonNull Bitmap bitmap, @Nullable Transition<? super Bitmap> 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<Bitmap>() {
@Override
public void onResourceReady(@NonNull Bitmap bitmap, @Nullable Transition<? super Bitmap> 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
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".mvp.ui.activity.ShowImageActivity"
>
<com.vondear.rxui.view.scaleimage.RxScaleImageView
android:id="@+id/Rx_imageView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#000000"/>
</LinearLayout>