0

I am trying to do:

fun getBitmap(uri: String?) {
    val imagePipeline = Fresco.getImagePipeline()
    val builder = ImageRequestBuilder.newBuilderWithSource(Uri.fromFile(File(uri)))
    val request = builder.build()
    val dataSource = imagePipeline.fetchDecodedImage(request, this)
    try {
        dataSource.subscribe(object : BaseBitmapDataSubscriber() {
            override fun onFailureImpl(dataSource: DataSource<CloseableReference<CloseableImage>>?) {
                Log.d("loadBackground", "fail")
            }

            override fun onNewResultImpl(bitmap: Bitmap?) {
                activity_levels.background = BitmapDrawable(resources, bitmap)
            }

            }, DefaultExecutorSupplier(1).forBackgroundTasks())
        } finally {
            dataSource?.close()
        }
    }

This is uri:

uri = "${directory.absolutePath}/background.jpg"

I always get into a method onFailureImpl with error java.lang.IllegalArgumentException: Unsupported uri scheme! Uri is...

How to upload image from internal storage?

pavel163
  • 145
  • 3
  • 7

1 Answers1

0

You can just use

ImageRequest request = ImageRequest.fromFile(yourFile)

to get your image request

However, if you're using the Bitmap directly (like you do), you need to hold on to the CloseableReference and manage the lifecycle for the data, see http://frescolib.org/docs/writing-custom-views.html

Alexander Oprisnik
  • 1,212
  • 9
  • 9