Skip to content
This repository has been archived by the owner on Feb 6, 2023. It is now read-only.

SVGACanvasDrawer.kt Smart cast to 'Bitmap!' is impossible, because 'textBitmap' is a local variable that is captured by a changing closure #431

Open
AhmedHumk opened this issue May 29, 2022 · 4 comments

Comments

@AhmedHumk
Copy link

i got this error in SVGACanvasDrawer.kt:

val textCanvas = Canvas(textBitmap)

@PonyCui
Copy link
Member

PonyCui commented May 29, 2022

Can you provide may context?

@AhmedHumk
Copy link
Author

AhmedHumk commented May 29, 2022

the whole code i am using the latest androidstudio bumblebee

var textBitmap: Bitmap? = null
        dynamicItem.dynamicText[imageKey]?.let { drawingText ->
            dynamicItem.dynamicTextPaint[imageKey]?.let { drawingTextPaint ->
                drawTextCache[imageKey]?.let {
                    textBitmap = it
                } ?: kotlin.run {
                    textBitmap = Bitmap.createBitmap(drawingBitmap.width, drawingBitmap.height, Bitmap.Config.ARGB_8888)
                    val drawRect = Rect(0, 0, drawingBitmap.width, drawingBitmap.height)
                    val textCanvas = Canvas(textBitmap)
                    drawingTextPaint.isAntiAlias = true
                    val fontMetrics = drawingTextPaint.getFontMetrics();
                    val top = fontMetrics.top
                    val bottom = fontMetrics.bottom
                    val baseLineY = drawRect.centerY() - top / 2 - bottom / 2
                    textCanvas.drawText(drawingText, drawRect.centerX().toFloat(), baseLineY, drawingTextPaint);
                    drawTextCache.put(imageKey, textBitmap as Bitmap)
                }
            }

@PonyCui
Copy link
Member

PonyCui commented May 29, 2022

Seems you are trying to draw text into a layer with custom bitmap.
Maybe you can see this sample https://github.com/svga/SVGAPlayer-Android/wiki/Dynamic-Drawer

@AhmedHumk
Copy link
Author

AhmedHumk commented May 29, 2022 via email

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants