I
I
Igor2020-01-28 21:48:14
Android
Igor, 2020-01-28 21:48:14

Rxjava load, save and display images in one pipeline?

Bottom line: you need to load the image, save it and display it. Everything works, but I don't like the current code:

Single.fromCallable { call.execute() }
            .map { it.body?.byteStream() }
            .map { BitmapFactory.decodeStream(it) }
            .map {//это мне не нравится
                it.compress(Bitmap.CompressFormat.JPEG, 90, getOutPutStream())
                it
            }
            .subscribeOn(Schedulers.io())
            .observeOn(AndroidSchedulers.mainThread())
            .subscribeBy({ it.printStackTrace() }, {
                imageView.setImageBitmap(it)

            })

I have poor knowledge of Rx, but it seems to me that this approach is not correct. The question is how to write it beautifully. Not to take out the received bitmap as a separate variable and then create a new pipeline with it? How to perform several unrelated operations in one pipeline?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Denis Zagaevsky, 2020-01-28
@Nigtime456

This approach is wrong. Use Glide to upload images.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question