像素介绍:适用于Android的新Kotlin图像加载库

I am thrilled and excited to announce Pixel, an open-source image loading library for Android built in Kotlin. It’s reliable, modern, and lightweight.

我很高兴和高兴地宣布Pixel ,这是一个在Kotlin中构建的Android开源图像加载库。 它可靠,现代且轻巧。

Tech stack: Kotlin coroutines, OkHttp, Okio, and AndroidX.

技术堆栈:Kotlin协程,OkHttp,Okio和AndroidX。

一个新的Kotlin图像加载库 (A New Kotlin Image Loading Library)

The idea of using Kotlin coroutines for structured concurrency and threading partly came from another similar library, Coil, which is the first image loading library built entirely in Kotlin. This is the second.

使用Kotlin协程进行结构化并发和线程处理的想法部分来自另一个类似的库Coil ,这是第一个完全在Kotlin中构建的图像加载库。 这是第二个。

Displaying images is an important part of many Android applications and developers often struggle to choose a library based on its sheer size and impact on their app — even regardless of its performance and perks. Common factors to consider are APK size, boilerplate code or its generation, and slower build times. This is where Pixel steps in.

显示图像是许多Android应用程序的重要组成部分,并且开发人员常常难以根据其绝对大小和对应用程序的影响来选择一个库,即使它的性能和特权如何也是如此。 要考虑的常见因素是APK大小,样板代码或其生成以及较慢的构建时间。 这就是Pixel介入的地方。

Here’s what a sample of Pixel looks like:

以下是Pixel的示例:

// Loads an image without a placeholder.
Pixel.load("https://example.com/image.jpg", iv)


// Loads an image with a placeholder resource.
Pixel.load("https://example.com/image.jpg", iv3, PixelOptions.Builder().setPlaceholderResource(R.drawable.ic_loading_android).build())


// Loads an image of 30x30 pixels with a placeholder resource.
Pixel.load("https://example.com/image.jpg", holder.iv, PixelOptions.Builder().setPlaceholderResource(R.drawable.ic_loading_android)
.setImageSize(30, 30).build())

Pixel is fairly new and under periodic development, so for now, only loading images from the internet is supported.

Pixel相当新,并且正在定期开发中,因此目前仅支持从Internet加载图像。

为什么选择像素? (Why Pixel?)

Many image loading libraries are out there, but Pixel loads an image based on the size (width x height) of the image view in pixels — hence the name. It’s created to fill the exact purpose of simpler image loading in Android. These are its core features:

那里有许多图像加载库,但是Pixel会根据以像素为单位的图像视图的大小(宽度x高度)加载图像(因此命名)。 它的创建是为了填补Android中简化图像加载的确切目的。 这些是其核心功能:

  • Kotlin-first: Pixel is built in Kotlin and leverages its idiomatics, inlining, extension, and lambda methods to create a simple and flexible API.

    Kotlin优先: Pixel内置于Kotlin中,并利用其惯用语言,内联,扩展和lambda方法来创建简单而灵活的API。

  • Kotlin coroutines: Pixel uses them for the same reasons as Coil does.

    Kotlin协程:Pixel使用它们的原因与Coil相同。
  • Reliable: Pixel’s tech stack is OkHttp and Okio, as they are standard for most apps relying on I/O operations. It also has AndroidX capability to keep in sync with the Android lifecycle.

    可靠:Pixel的技术堆栈是OkHttp和Okio,因为它们是大多数依赖I / O操作的应用程序的标准配置。 它还具有AndroidX功能,可与Android生命周期保持同步。
  • Responsive UI: Pixel is responsive to the main thread’s state. It ensures that any image load requested on the main thread is subject to the availability of the main thread. For this purpose, it uses the provided imageView and posts the load to it in case of any other main thread state becomes available.

    响应式用户界面:Pixel响应主线程的状态。 这样可以确保在主线程上请求的任何图像加载都受主线程可用性的限制。 为此,它使用提供的imageView并在其他任何主线程状态变为可用的情况下将负载发布到它。
  • Signature download: Each image load is unique. Pixel performs optimizations by tracking and identifying each load so that the same image with the same params (size) isn’t downloaded.

    签名下载: 每个图像加载都是唯一的。 Pixel通过跟踪和识别每个负载来执行优化,从而不会下载具有相同参数(大小)的相同图像。

  • Lightweight: Another main purpose behind Pixel is being extremely lightweight without compromising its performance to avoid its dependency being a relevant factor for consideration. To ensure strict adherence to the single-responsibility principle, Pixel is miniature optimized. No extra features are or will be added. Some examples are applying animations on imageView, modifying an imageView, or applying its properties on it (which can and should be set from the client’s side). Also, there is no annotation processing to avoid slowing down the build speed.

    轻巧: Pixel的另一个主要目的是在不损害其性能的前提下实现极其轻巧的性能,以避免其依赖性成为要考虑的相关因素。 为了确保严格遵守单一责任原则,对像素进行了微型优化。 没有额外的功能被添加或将被添加。 一些示例是在imageView上应用动画,修改imageView或在其上应用其属性(可以并且应该从客户端设置)。 另外,没有注释处理可以避免降低构建速度。

  • Testable: Pixel primarily uses a singleton artifact it can be wrapped around to create mock tests.

    可测试的: Pixel主要使用单件伪影,可以将其包裹起来以创建模拟测试。

入门 (Getting Started)

I am extremely delighted to be sharing Pixel with the community. The repo contains quickstart, while full documentation will be added soon. Stay tuned! Also, any relevant enhancement suggestions are welcome and can be reported on GitHub.

我非常高兴能与社区分享Pixel 。 该回购包含快速入门,而完整的文档将很快添加。 敬请关注! 此外,欢迎任何相关的增强建议,并可以在GitHub上进行报告。

翻译自: https://medium.com/better-programming/introducing-pixel-a-new-kotlin-image-loading-library-for-android-a37a7a192f73

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值