我想从URL加载一个位图,然后使用调色板API从其中获得一些颜色。
在文档页面上,我找不到直接获取位图的代码!
有人能帮我吗?
发布于 2020-05-19 22:06:50
您可以使用target方法并将可绘制内容强制转换为bitmap
val loader = ImageLoader(this)
val req = ImageRequest.Builder(this)
.data("https://images.dog.ceo/breeds/saluki/n02091831_3400.jpg") // demo link
.target { result ->
val bitmap = (result as BitmapDrawable).bitmap
}
.build()
val disposable = loader.enqueue(req)如果你使用协程,那么在你的CoroutineScope中使用GetRequest (带有suspend的重载execute方法):
coroutineScope.launch{
val loader = ImageLoader(this)
val request = ImageRequest.Builder(this)
.data("https://images.dog.ceo/breeds/saluki/n02091831_3400.jpg")
.allowHardware(false) // Disable hardware bitmaps.
.build()
val result = (loader.execute(request) as SuccessResult).drawable
val bitmap = (result as BitmapDrawable).bitmap
}https://stackoverflow.com/questions/61892301
复制相似问题