zoukankan      html  css  js  c++  java
  • android开发使用Glide加载Bitmap的方法

    方法一:不推荐,会出现闪烁
    fun loadBitmapImage(target: ImageView, bitmap: Bitmap) {
    val baos = ByteArrayOutputStream()
    bitmap.compress(Bitmap.CompressFormat.PNG, 100, baos)
    val bytes: ByteArray = baos.toByteArray()
    val requestOptions = RequestOptions().centerCrop()
    Glide.with(target.context)
    .setDefaultRequestOptions(requestOptions)
    .load(bytes)
    .into(target)
    baos.closeQuietly()
    }

    方法二:推荐
    fun loadBitmapImage(target: ImageView, bitmap: Bitmap) { val drawable
    = BitmapDrawable(target.resources, bitmap) val requestOptions = RequestOptions().centerCrop() .diskCacheStrategy(DiskCacheStrategy.ALL) .error(drawable)  //放在出错位置 .placeholder(drawable)  //放在占位符位置 Glide.with(target.context) .setDefaultRequestOptions(requestOptions) .load("https://${System.currentTimeMillis()}")  //随便给个不可用的url .into(target) }
  • 相关阅读:
    attr与prop
    Django框架学习
    库的操作
    javascript 基础知识
    进程
    正则表达式
    模块( collections , time , random , os , sys)
    内置函数
    生成器
    迭代器
  • 原文地址:https://www.cnblogs.com/yongfengnice/p/13488858.html
Copyright © 2011-2022 走看看