I wrote a program in Android for setting different kinds of images as my background image, but it is not working with svg files. I am not getting any errors, it is not displaying any image and I'm getting a blank screen in my emulator when using svg files. Can any one suggest how to read and display svg files in Android with some code? Or should I convert xml code?
Asked
Active
Viewed 8,777 times
4
-
@user I understand that English may not be your first language, but Ross is right. If you take the time to look up the correct spelling of words, and don't use lots of ".........." for no reason, then people will be much more likely to want to help you out. – Tyler Nov 23 '10 at 06:47
3 Answers
4
Check out Batik. It's a library for creating and parsing SVG in java. It's part of the Apache XML Graphics Project.
Update:
As it turns out, getting Batik to work on Android is non-trivial and there are easier ways to work with SVG on Android. See this answer for more detail.
-
2Batik is pure java and open source. If it's not supported natively on the Android platform, you might try compiling it from source and bundling it with your project. – Asaph Nov 10 '10 at 05:51
-
kk......throhgh batik we can create some 2d graphics .......bt as im new to java and android i want to know whether i can read a svg file from batik – user493244 Nov 10 '10 at 06:02
-
kk ...thank you ........i will try n i vl let u know if any prob vl arise........ – user493244 Nov 10 '10 at 06:22
-
k ....in the above issue if i want to display the svg image as my background whether i must import some lib files from batik? – user493244 Nov 10 '10 at 06:25
-
You probably will need some files from Batik. Android doesn't use java class files so you'll probably have to compile the java source for Batik to native Android dex files for them to be useful. It may be a lot of files too. – Asaph Nov 10 '10 at 06:43
-
The answer won't fit in a comment. Please ask a separate question for that. – Asaph Nov 10 '10 at 15:19
-
-1. Batik uses Java2d to render SVG. Android does not support Java2D, and has its own custom graphics API instead, so I would not expect Batik to work OOTB on Android. Getting Batik to work on Android would, in fact, involve a significant porting effort. – jbeard4 Sep 14 '11 at 18:23
-
@echo-flow: You're right. I was speculating. I've updated my answer to include this info and a link to another more useful answer. – Asaph Sep 14 '11 at 21:59
0
Another alternative is AndroidSVG (http://code.google.com/p/androidsvg/).
Paul LeBeau
- 91,047
- 8
- 141
- 167
0
If you can afford to only support Android versions greater than 3, then you could use a Webkit instance to render SVG, as the Android Webkit browser finally has SVG support compiled in.
Alternatively, if you do not require support for scripting or animation, you try using this library: http://code.google.com/p/svg-android/
jbeard4
- 12,238
- 4
- 54
- 66
-
I think this answer is referring to browser-based apps on android, as opposed to native-apps on android ? – dsdsdsdsd Apr 22 '16 at 14:09