Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Memory error #130

Open
hafiz013 opened this issue Dec 30, 2024 · 0 comments
Open

Memory error #130

hafiz013 opened this issue Dec 30, 2024 · 0 comments

Comments

@hafiz013
Copy link

hafiz013 commented Dec 30, 2024

Error Code:

Canvas: trying to draw too large(116928000bytes) bitmap.
	at android.graphics.RecordingCanvas.throwIfCannotDraw(RecordingCanvas.java:266)

this sample code not working anymore after update library:

val kamelConfig = remember {
            KamelConfig {
                takeFrom(KamelConfig.Default)
                fetcher(object : Fetcher<ByteArray> {
                    override val inputDataKClass: KClass<ByteArray>
                        get() = ByteArray::class
                    override val source: DataSource
                        get() = DataSource.Memory

                    override fun fetch(
                        data: ByteArray,
                        resourceConfig: ResourceConfig
                    ): Flow<Resource<ByteReadChannel>> = flow {
                        val byteReadChannel = ByteReadChannel(data)
                        emit(Resource.Success(byteReadChannel, source))
                    }

                    override val ByteArray.isSupported: Boolean
                        get() = true

                })

            }
        }
        CompositionLocalProvider(LocalKamelConfig provides kamelConfig) {
            App(iosPlatformModules)
        }

but now .Default :

KamelConfig {
    imageBitmapCacheSize = DefaultCacheSize
    imageVectorCacheSize = DefaultCacheSize
    svgCacheSize = DefaultCacheSize
    imageBitmapDecoder()
    imageVectorDecoder()
    svgDecoder()
    stringMapper()
    urlMapper()
    uriMapper()
    fileFetcher()
    httpFetcher {
        httpCache(DefaultHttpCacheSize)
    }
    platformSpecificConfig()
}

.Core

KamelConfig {
        imageBitmapCacheSize = DefaultCacheSize
        imageVectorCacheSize = DefaultCacheSize
        svgCacheSize = DefaultCacheSize
        animatedImageCacheSize = DefaultCacheSize
        stringMapper()
        urlMapper()
        uriMapper()
        fileFetcher()
        fileUrlFetcher()
        httpUrlFetcher {
            httpCache(DefaultHttpCacheSize)
        }
    }

Note: missing imageBitmapDecoder

Question : If the file size is type jpg and dimensions 5760x5760. Then how to resize it become small before can load using this function:

KamelImage(
                        resource = asyncPainterResource(imageUrl),
                        contentDescription = null,
                        onLoading = {
                            CustomImage(
                                painterResource(Res.drawable.image_holder),
                                Modifier
                                    .align(Alignment.Center)
                            )
                        },
                        onFailure = {
                            CustomImage(
                                painterResource(Res.drawable.image_holder),
                                Modifier
                                    .align(Alignment.Center)
                            )
                        },
                        contentScale = ContentScale.Crop,
                        modifier = Modifier.fillMaxSize(),
                        animationSpec = tween()
                    )
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant