问题
I have an SVG file format in which there is 5-6 icon and I need to pick icon according to the requirement not the whole Image.
In Simply you can parse the .SVG onto your ImageView Or Canvas but this time I need to choose particular icon from the among.
Is this possible to do with the coding or i need to draw all icon separately ?
Somebody suggest me the way, how to make it happen ?
回答1:
I did not try it but you may :
- Create a Bitmap with the size of your icon
- Create a new Canvas associated to this Bitmap
- Draw your svg into the Canvas with an offset -- If your icon coordinates are (X1, Y1) -- Then when you draw an element substract SVG (X1, Y1)
- Draw the Bitmap on screen.
It is a little bit homemade solution... maybe there is some libraries doing those king of things for you.
回答2:
You could set a clip and translation on the canvas before drawing to hide all but the icon you want, but I think the best course of action is to use separate image files.
回答3:
You don't say which SVG library you are using. If you are using AndroidSVG, you could add <view> elements to your SVG (one for each icon) and select the appropriate icon to draw using renderViewToPicture() etc.
来源:https://stackoverflow.com/questions/18713383/a-svg-image-have-6-icon-and-need-to-choose-one