我正在尝试:
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()
}
}
这是uri:
uri = "${directory.absolutePath}/background.jpg"
我总是遇到错误 java.lang.IllegalArgumentException:不支持的uri方案的方法onFailureImpl
! Uri是......
如何从内部存储上传图片?
答案 0 :(得分:0)
你可以使用
ImageRequest request = ImageRequest.fromFile(yourFile)
获取您的图片请求
但是,如果您直接使用位图(就像您一样),则需要保留CloseableReference
并管理数据的生命周期,请参阅http://frescolib.org/docs/writing-custom-views.html