MeshCentralAndroidAgent icon indicating copy to clipboard operation
MeshCentralAndroidAgent copied to clipboard

users account image not shown if png

Open si458 opened this issue 11 months ago • 0 comments

so it appears if a users account image in meshcentral is PNG, then its not shown in the app

function getUserImage inside of MeshAgent.kt

if ((ximage != null) && (!ximage.startsWith("data:image/jpeg;base64,"))) { ximage = null; }

fix

if ((ximage != null) && 
    (!ximage.startsWith("data:image/jpeg;base64,") && 
     !ximage.startsWith("data:image/png;base64,"))) {
    ximage = null
}

if (ximage != null) {
    try {
        // Determine the start index for decoding
        val base64Prefix = when {
            ximage.startsWith("data:image/jpeg;base64,") -> "data:image/jpeg;base64,"
            ximage.startsWith("data:image/png;base64,") -> "data:image/png;base64,"
            else -> ""
        }
        
        // Decode the image after removing the base64 header
        val imageBytes = android.util.Base64.decode(ximage.substring(base64Prefix.length), 0)
        xuserImage = BitmapFactory.decodeByteArray(imageBytes, 0, imageBytes.size)

        // Round the image edges
        val imageRounded = Bitmap.createBitmap(xuserImage.width, xuserImage.height, xuserImage.config)
        val canvas = Canvas(imageRounded)
        val mpaint = Paint()
        mpaint.isAntiAlias = true
        mpaint.shader = BitmapShader(xuserImage, Shader.TileMode.CLAMP, Shader.TileMode.CLAMP)
        canvas.drawRoundRect(RectF(0F, 0F, xuserImage.width.toFloat(), xuserImage.height.toFloat()), 32F, 32F, mpaint)

        xuserImage.recycle()
        xuserImage = imageRounded
    } catch (ex: java.lang.Exception) {
        // Handle exceptions here
    }
}

si458 avatar Dec 31 '24 21:12 si458