com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool

package com.bumptech.glide.load.engine.bitmap_recycle;

import android.graphics.Bitmap;
import android.support.annotation.NonNull;

/**
 * An interface for a pool that allows users to reuse {@link android.graphics.Bitmap} objects.
 */
public interface BitmapPool {

  /**
   * Returns the current maximum size of the pool in bytes.
   */
  int getMaxSize();

  /**
   * Multiplies the initial size of the pool by the given multiplier to dynamically and
   * synchronously allow users to adjust the size of the pool.
   *
   * <p> If the current total size of the pool is larger than the max size after the given
   * multiplier is applied, {@link Bitmap}s should be evicted until the pool is smaller than the new
   * max size. </p>
   *
   * @param sizeMultiplier The size multiplier to apply between 0 and 1.
   */
  void setSizeMultiplier(float sizeMultiplier);

  /**
   * Adds the given {@link android.graphics.Bitmap} if it is eligible to be re-used and the pool
   * can fit it, or calls {@link Bitmap#recycle()} on the Bitmap and discards it.
   *
   * <p> Callers must <em>not</em> continue to use the Bitmap after calling this method. </p>
   *
   * @param bitmap The {@link android.graphics.Bitmap} to attempt to add.
   * @see android.graphics.Bitmap#isMutable()
   * @see android.graphics.Bitmap#recycle()
   */
  void put(Bitmap bitmap);

  /**
   * Returns a {@link android.graphics.Bitmap} of exactly the given width, height, and
   * configuration, and containing only transparent pixels.
   *
   * <p> If no Bitmap with the requested attributes is present in the pool, a new one will be
   * allocated. </p>
   *
   * <p> Because this method erases all pixels in the {@link Bitmap}, this method is slightly slower
   * than {@link #getDirty(int, int, android.graphics.Bitmap.Config)}. If the {@link
   * android.graphics.Bitmap} is being obtained to be used in {@link android.graphics.BitmapFactory}
   * or in any other case where every pixel in the {@link android.graphics.Bitmap} will always be
   * overwritten or cleared, {@link #getDirty(int, int, android.graphics.Bitmap.Config)} will be
   * faster. When in doubt, use this method to ensure correctness. </p>
   *
   * <pre>
   *     Implementations can should clear out every returned Bitmap using the following:
   *
   * {@code
   * bitmap.eraseColor(Color.TRANSPARENT);
   * }
   * </pre>
   *
   * @param width  The width in pixels of the desired {@link android.graphics.Bitmap}.
   * @param height The height in pixels of the desired {@link android.graphics.Bitmap}.
   * @param config The {@link android.graphics.Bitmap.Config} of the desired {@link
   *               android.graphics.Bitmap}.
   * @see #getDirty(int, int, android.graphics.Bitmap.Config)
   */
  @NonNull
  Bitmap get(int width, int height, Bitmap.Config config);

  /**
   * Identical to {@link #get(int, int, android.graphics.Bitmap.Config)} except that any returned
   * {@link android.graphics.Bitmap} may <em>not</em> have been erased and may contain random data.
   *
   * <p>If no Bitmap with the requested attributes is present in the pool, a new one will be
   * allocated. </p>
   *
   * <p> Although this method is slightly more efficient than {@link #get(int, int,
   * android.graphics.Bitmap.Config)} it should be used with caution and only when the caller is
   * sure that they are going to erase the {@link android.graphics.Bitmap} entirely before writing
   * new data to it. </p>
   *
   * @param width  The width in pixels of the desired {@link android.graphics.Bitmap}.
   * @param height The height in pixels of the desired {@link android.graphics.Bitmap}.
   * @param config The {@link android.graphics.Bitmap.Config} of the desired {@link
   *               android.graphics.Bitmap}.
   * @return A {@link android.graphics.Bitmap} with exactly the given width, height, and config
   * potentially containing random image data or null if no such {@link android.graphics.Bitmap}
   * could be obtained from the pool.
   * @see #get(int, int, android.graphics.Bitmap.Config)
   */
  @NonNull
  Bitmap getDirty(int width, int height, Bitmap.Config config);

  /**
   * Removes all {@link android.graphics.Bitmap}s from the pool.
   */
  void clearMemory();

  /**
   * Reduces the size of the cache by evicting items based on the given level.
   *
   * @param level The level from {@link android.content.ComponentCallbacks2} to use to determine how
   *              many {@link android.graphics.Bitmap}s to evict.
   * @see android.content.ComponentCallbacks2
   */
  void trimMemory(int level);
}
package com.bumptech.glide.load.engine.bitmap_recycle;

import android.graphics.Bitmap;
import android.support.annotation.NonNull;

/**
 * An interface for a pool that allows users to reuse {@link android.graphics.Bitmap} objects.
 */
public interface BitmapPool {

  /**
   * Returns the current maximum size of the pool in bytes.
   */
  int getMaxSize();

  /**
   * Multiplies the initial size of the pool by the given multiplier to dynamically and
   * synchronously allow users to adjust the size of the pool.
   *
   * <p> If the current total size of the pool is larger than the max size after the given
   * multiplier is applied, {@link Bitmap}s should be evicted until the pool is smaller than the new
   * max size. </p>
   *
   * @param sizeMultiplier The size multiplier to apply between 0 and 1.
   */
  void setSizeMultiplier(float sizeMultiplier);

  /**
   * Adds the given {@link android.graphics.Bitmap} if it is eligible to be re-used and the pool
   * can fit it, or calls {@link Bitmap#recycle()} on the Bitmap and discards it.
   *
   * <p> Callers must <em>not</em> continue to use the Bitmap after calling this method. </p>
   *
   * @param bitmap The {@link android.graphics.Bitmap} to attempt to add.
   * @see android.graphics.Bitmap#isMutable()
   * @see android.graphics.Bitmap#recycle()
   */
  void put(Bitmap bitmap);

  /**
   * Returns a {@link android.graphics.Bitmap} of exactly the given width, height, and
   * configuration, and containing only transparent pixels.
   *
   * <p> If no Bitmap with the requested attributes is present in the pool, a new one will be
   * allocated. </p>
   *
   * <p> Because this method erases all pixels in the {@link Bitmap}, this method is slightly slower
   * than {@link #getDirty(int, int, android.graphics.Bitmap.Config)}. If the {@link
   * android.graphics.Bitmap} is being obtained to be used in {@link android.graphics.BitmapFactory}
   * or in any other case where every pixel in the {@link android.graphics.Bitmap} will always be
   * overwritten or cleared, {@link #getDirty(int, int, android.graphics.Bitmap.Config)} will be
   * faster. When in doubt, use this method to ensure correctness. </p>
   *
   * <pre>
   *     Implementations can should clear out every returned Bitmap using the following:
   *
   * {@code
   * bitmap.eraseColor(Color.TRANSPARENT);
   * }
   * </pre>
   *
   * @param width  The width in pixels of the desired {@link android.graphics.Bitmap}.
   * @param height The height in pixels of the desired {@link android.graphics.Bitmap}.
   * @param config The {@link android.graphics.Bitmap.Config} of the desired {@link
   *               android.graphics.Bitmap}.
   * @see #getDirty(int, int, android.graphics.Bitmap.Config)
   */
  @NonNull
  Bitmap get(int width, int height, Bitmap.Config config);

  /**
   * Identical to {@link #get(int, int, android.graphics.Bitmap.Config)} except that any returned
   * {@link android.graphics.Bitmap} may <em>not</em> have been erased and may contain random data.
   *
   * <p>If no Bitmap with the requested attributes is present in the pool, a new one will be
   * allocated. </p>
   *
   * <p> Although this method is slightly more efficient than {@link #get(int, int,
   * android.graphics.Bitmap.Config)} it should be used with caution and only when the caller is
   * sure that they are going to erase the {@link android.graphics.Bitmap} entirely before writing
   * new data to it. </p>
   *
   * @param width  The width in pixels of the desired {@link android.graphics.Bitmap}.
   * @param height The height in pixels of the desired {@link android.graphics.Bitmap}.
   * @param config The {@link android.graphics.Bitmap.Config} of the desired {@link
   *               android.graphics.Bitmap}.
   * @return A {@link android.graphics.Bitmap} with exactly the given width, height, and config
   * potentially containing random image data or null if no such {@link android.graphics.Bitmap}
   * could be obtained from the pool.
   * @see #get(int, int, android.graphics.Bitmap.Config)
   */
  @NonNull
  Bitmap getDirty(int width, int height, Bitmap.Config config);

  /**
   * Removes all {@link android.graphics.Bitmap}s from the pool.
   */
  void clearMemory();

  /**
   * Reduces the size of the cache by evicting items based on the given level.
   *
   * @param level The level from {@link android.content.ComponentCallbacks2} to use to determine how
   *              many {@link android.graphics.Bitmap}s to evict.
   * @see android.content.ComponentCallbacks2
   */
  void trimMemory(int level);
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
### 回答1: com.bumptech.glide.glide是一个Android平台上的图片加载库,它可以帮助开发者快速、高效地加载图片,并支持各种图片格式和加载方式。它的特点是易于使用、可定制性强、支持多种图片格式和加载方式、性能优秀等。在Android开发中,使用com.bumptech.glide.glide可以帮助我们更好地管理和加载图片,提高应用的用户体验。 ### 回答2: com.bumptech.glide.glide 是一个Android图片加载库,旨在使在Android上显示图片变得更加简单。它提供了一个丰富的API,可以实现各种不同类型的图片加载,包括网络、本地、资源、assets等多种来源。常见的图片格式也都被支持,如JPEG、PNG、GIF等。 除了以上图片加载相关的基本功能外,com.bumptech.glide.glide 还提供了许多功能扩展,比如支持对图片的缩放、裁剪、动画等操作,可以在需要时对图片进行相应的处理。同时,它还支持加载gif动画,并可以通过监听器获取图片加载的状态和进度信息,更加灵活地处理图片加载过程。 另外,com.bumptech.glide.glide 也具有一定的可定制性,用户可以通过使用Module的方式,自定义图片加载的一些行为。比如加入自定义的Decoder、Encoder等组件,使得加载的行为更加符合实际需求。 作为一款强大而简单易用的图片加载库,com.bumptech.glide.glide 的使用非常广泛。它被许多知名应用程序选择作为图片加载的库,如Google Photos、Guardian、Evernote等。同时,在GitHub上也有较多的开源项目使用它,如JustEditor、Android-Multi-Language-Library等。 综上所述,com.bumptech.glide.glide 是一款功能丰富、可定制性高、使用简单的Android图片加载库,应用广泛且不断更新迭代,是目前Android平台上图片加载的一个非常优秀的解决方案。 ### 回答3: com.bumptech.glide.glide 是一个流行的 Android 图像加载库,它可以帮助开发者高效地加载和处理图片。Glide 支持从各种数据源加载图片,包括网络、本地储存、视频、GIF 和接收者等。 Glide 的 API 设计简单直观,易于使用,同时也可提供高度的配置性,可以满足不同的应用需求。Glide 还提供了多种配置选项,例如调整图片大小、修改缓存策略、自定义转换器、设置占位符等等,这些功能都可以通过简单的 API 调用来完成。 Glide 还可以帮助开发者更加高效地加载大量的图片。它可以自动管理图片加载过程中的内存占用、请求优先级以及生命周期等,从而更好地实现了图片的流畅加载和渲染。 与其他 Android 图像加载库相比,Glide 优势明显。首先,Glide 提供了非常好的占位符配置选项和灵活的图片尺寸选项等,这些功能为用户带来舒适的用户体验和更快的图片加载速度。其次,Glide 具有完善的生命周期管理和内存处理机制,可以自动控制内存使用和图片缓存,减少应用程序因图片加载而导致崩溃的风险。 综上所述,com.bumptech.glide.glide 是一种方便快捷且功能丰富的 Android 图像加载库,它可以帮助应用程序更加高效地处理图片,提高用户的体验,同时也有助于开发者简化代码并提高开发效率。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值