https://github.com/ltttttttttttt/load-the-image
桌面端图片加载框架, load-the-image Apply to compose-jb(desktop), Used to load network and local pictures, supports caching.
https://github.com/ltttttttttttt/load-the-image
compose compose-jb desktop desktopimageloader imageloader kmm kmp kotlin kotlin-library loadimagefromurl
Last synced: 3 months ago
JSON representation
桌面端图片加载框架, load-the-image Apply to compose-jb(desktop), Used to load network and local pictures, supports caching.
- Host: GitHub
- URL: https://github.com/ltttttttttttt/load-the-image
- Owner: ltttttttttttt
- License: apache-2.0
- Created: 2022-04-06T07:58:20.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2024-04-23T03:07:46.000Z (over 1 year ago)
- Last Synced: 2024-04-23T06:23:07.433Z (over 1 year ago)
- Topics: compose, compose-jb, desktop, desktopimageloader, imageloader, kmm, kmp, kotlin, kotlin-library, loadimagefromurl
- Language: Kotlin
- Homepage:
- Size: 698 KB
- Stars: 32
- Watchers: 1
- Forks: 3
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
[简体中文](https://blog.csdn.net/qq_33505109/article/details/125194044)
# load-the-image
load-the-image Apply to compose-jb(desktop), Used to load network and local pictures.
Example:

Mode of use
Use the code load image with network, file, resources and more
```kotlin
//url="https://img.zcool.cn/community/017e625e57415ea801216518c25819.jpg@1280w_1l_2o_100sh.jpg"
Image(rememberImagePainter(url), "")
```Add to your project
Step 1.Root dir, build.gradle.kts add:
```kotlin
buildscript {
repositories {
maven("https://jitpack.io")//this
...
}
}allprojects {
repositories {
maven("https://jitpack.io")//this
...
}
}
```Step 2.Your compose-desktop dir, build.gradle.kts add:
version = [](https://jitpack.io/#ltttttttttttt/load-the-image)
```kotlin
kotlin {
sourceSets {
val jvmMain by getting {
dependencies {
...
implementation("com.github.ltttttttttttt:load-the-image:$version")//this
}
}
}
}
```Step 3.Recommendation: uniformly configure the failure graph path displayed when loading fails
```kotlin
fun main() {
LoadTheImageManager.defaultErrorImagePath = "drawable-xxhdpi/load_error.jpeg"//this
application {
Window(onCloseRequest = ::exitApplication) {
MaterialTheme {
Image(rememberImagePainter("https://img.zcool.cn/community/017e625e57415ea801216518c25819.jpg@1280w_1l_2o_100sh.jpg"),"")
}
}
}
}
```ps:Reference of Resource location, you can customize

Step 4.Recommendation: set the version of Compose-jb(desktop) to 1.1.1 or above
According to the feedback, it is found that there is a bug in the 1.1.0 version of compose JB, which will not start
Custom configuration
1.Configure placeholder and error image
You can use the default parameters in the method

Usage:
```kotlin
rememberImagePainter(url, /*the placeholder path*/)
```Or:
```kotlin
rememberImagePainter(DataToBeLoaded(url).apply {
placeholderResource = /*the placeholder path*/
errorImagePath = /*the error resource path*/
})
```2.Modify memory cache size
```kotlin
LoadTheImageManager.memoryCache = ImageLruMemoryCache(/*max memory cache size*/)
```ps:Default memory cache size:maxOf(50MB, 1% of total memory)
You can customize:
```kotlin
LoadTheImageManager.memoryCache = /*your class*/
```3.Modify file cache location
```kotlin
LoadTheImageManager.fileCache = ImageFileCache(File("C://test_dir"))
```Or:
```kotlin
LoadTheImageManager.fileCache = /*your class*/
```ps:Default file cache location: user\Pictures\LoadTheImageCache
4.Modify http loader
```kotlin
LoadTheImageManager.httpLoader = /*your class*/
```5.Load-the-image supports multiple formats, And it can be expanded by itself

Custom reference below:
One.Implement your class:

Two.Configure:
```kotlin
LoadTheImageManager.loadTheImage.add(ByteArrayLoadTheImage()/*your class*/)
```Three.Use:
```kotlin
rememberImagePainter(DataToBeLoaded(byteArrayOf()))//Better seal it
```If you use compose(Kotlin Multiplatform), You can refer to the example.
version = [](https://jitpack.io/#ltttttttttttt/load-the-image)
Your common dir, build.gradle.kts add:
```kotlin
val desktopMain by getting{
dependencies {
implementation 'com.github.ltttttttttttt:load-the-image:$version'
}
}
```commonMain add function:
```kotlin
@Composable
expect fun rememberImagePainter(url: String): Painter
```androidMain add function(and other target):
```kotlin
@Composable
actual fun rememberImagePainter(url: String): Painter =
coil.compose.rememberImagePainter(data = url)
```desktopMain add function:
```kotlin
@Composable
actual fun rememberImagePainter(url: String): Painter =
com.lt.load_the_image.rememberImagePainter(url)
```
Use the code load image with network and file and resources```kotlin
Image(rememberImagePainter(/*url*/"https://img.zcool.cn/community/017e625e57415ea801216518c25819.jpg@1280w_1l_2o_100sh.jpg","")
```