Anyone here have any experience using SVG files in...
# android
m
Anyone here have any experience using SVG files in coil? I’m loading a 24x24 svg into my app, and if i don’t specify a size, it ends up huge (2621x2621). If I specify OriginalSize, then it comes in 24px x 24px. I would have assumed it would apply some sort of transformation for an svg to account for screen density.
i
being a vector format it’s natural that an SVG won’t have a “default” size. What are you trying to achieve?
m
well, svg’s do have a default size. it’s right in the file:
Copy code
<svg xmlns="<http://www.w3.org/2000/svg>" viewBox="0 0 24 24" fill="black" width="18px" height="18px">
i
is it possible that the originalsize is referring to the viewbox size?
m
yeah, the code for SvgDecoder treats originalSize as a fixed value, not scalable by screen resolution. If you don’t pass it a fixed size or ask for originalSize, it sizes it pretty big. I haven’t figured out exactly why it picks the size it does, but i imagine it has some default size or it calculates it based on screen size.
I can always make my own SvgDecoder. It’s pretty simple to alter the existing one:
Copy code
val resScalingFactor = context.resources.displayMetrics.density


is OriginalSize -> {
    if (svgWidth > 0 && svgHeight > 0) {
        bitmapWidth = (svgWidth * resScalingFactor).toInt()
        bitmapHeight = (svgHeight * resScalingFactor).toInt()
    } else {
        bitmapWidth = DEFAULT_SIZE
        bitmapHeight = DEFAULT_SIZE
    }
}
116 Views