All Downloads are FREE. Search and download functionalities are using the official Maven repository.

commonMain.com.seiko.imageloader.intercept.NinePatchInterceptor.kt Maven / Gradle / Ivy

The newest version!
package com.seiko.imageloader.intercept

import com.seiko.imageloader.asImageBitmap
import com.seiko.imageloader.model.ImageResult
import com.seiko.imageloader.model.ninePatchData
import com.seiko.imageloader.util.NinePatchPainter

// only support Bitmap
class NinePatchInterceptor : Interceptor {
    override suspend fun intercept(chain: Interceptor.Chain): ImageResult {
        val request = chain.request
        val result = chain.proceed(request)
        if (result is ImageResult.OfBitmap) {
            val centerSlice = request.ninePatchData ?: return result
            return ImageResult.OfPainter(
                painter = NinePatchPainter(
                    image = result.bitmap.asImageBitmap(),
                    ninePatchData = centerSlice,
                ),
            )
        }
        return result
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy