RxJava Retrofit2 读取web生成的图形验证码

Retrofit2 配置

@GET("/imageValidCode")
Observable getImageValidCode();

RxJava使用

authService.getImageValidCode()
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.map(responseBody -> body.byteStream())
.map(inputStream -> BitmapFactory.decodeStream(is))
.subscribe(bitmap -> view.showValidCode(bitmap));

界面上使用ImageView显示Bitmap

public void showValidCode(Bitmap bitmap){
    avatarIv.setImageBitmap(bitmap);
}

你可能感兴趣的:(Android)