Closed Arashvscode closed 1 year ago
It will depend on your SVG.
getDocumentWidth()
and getDocumentHeight()
return the values of the width
and height
attributes, respectively. Eg.
<svg width="200" height="150" ,,,>
If your SVG doesn't have those attributes, -1 will be returned.
Actually, all my svgs have this option, but it doesn't return anything for me. Is the code I wrote correct?
Can you attach one of your SVGs that doesn't work?
Yes, I connected it, but the result is nothing, it returns -1. Can you send me a correct code?
I meant please attach the SVG to this GitHub issue.
Is the code I wrote correct?
It looks correct. But results will depend on your SVG.
Actually, all my svgs have this option
I forgot to mention that the width
and height
need to be pixel values. For example width="100"
or width="100px"
. If the width
or height
use relative units like % or em
, you will get -1. For example, getDocumentWidth()
will return -1 for width="100%"
. That is because 100% is not a real measurement. It means "100% of the parent container width". But there is no parent container here to measure against.
Actually most of my svgs are 100% length and width, is this a bug in your library?
No. It is not a bug. It is working as intended.
Those methods were intended to return the dimensions of the SVG - if they were specified. But "100%" is not a true dimension. It means "100% of the viewport or parent container". But, without knowing those values, "100%" means nothing.
It probably would not be useful to display to your users "100% x 100%".
Is that is what you actually do want to display? If so, then unfortunately, AndroidSVG doesn't yet have a method to get the exactly value of the width
and height
attributes. For now you would need to fork the code and add those methods yourself.
I'd rather you add a converter feature to convert svg to png or vice versa
I don't have any plans to add that feature.
Hello, I use this code to display the length and width of the svg, but it does not work and produces 0 for me, can you help me?