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) }
  • 相关阅读:
    设计模式-适配器模式
    设计模式-模板方法模式
    设计模式-策略模式
    spring-消息
    spring-集成redis
    spring-mvc高级技术
    spring-AOP
    restful规范
    十一,装饰器详解
    十,函数对象,嵌套,名称空间与作用域,闭包函数
  • 原文地址:https://www.cnblogs.com/yongfengnice/p/13488858.html
Copyright © 2011-2022 走看看