I am having a requirement where I have to generate a single svg file from various svg file like shapes into the canvas in android platform like making a image. And above that after saving that svg file I can also re-import that svg file and can undo/redo the changes done previously as well as making adding new stuff and saving the new svg file.
I am not much aware regarding importing and reusing the svg file after once it is saved and redo/undo or edit the previous changes step by step according to the layers in svg file and additionally making new changes into it.
I had R&D in figuring out the way but could not find any helpful solution. It would be great help if anyone can suggest me convenient ways to do that so.
Thank you.
Related
We convert SVG into the simpler VectorDrawable format all the time for use in Android, but soon it becomes a maintenance issue and we never know if a VectorDrawable is up to date.
One way to do that is to keep the SVG in the source repo, but gitignore the VectorDrawable XML files; then to write a Makefile to generate the needed XML files. But given gradle is doing the same job as Makefile, there might be a better gradle way to do so?
It is desirable if we can skip the creation of VectorDrawable XML in source (i.e. build/intermediate would be great).
I am not looking for libraries to render SVG files at runtime. Just something to streamline the SVG-update -> Drawable XML update process, so developers can focus on coding instead of managing resources.Thanks!
I want to use vector asset in android studio to generate svg xml file,
I convert my png to svg in this web site
but when I use this svg file in vector asset to generate xml file, I get following error message
It display "could not generate a preview"
How can I fix it?
Most of the complaints on this topic are due to people trying to convert SVGs that use features of the SVG standard that are not supported by VectorDrawables. And the SVG to VectorDrawable converter in AndroidStudio only supports those limited features. It doesn't really give much feedback when it encounters things it doesn't support.
Some of the online converters try a bit harder. You might have better success with them.
Otherwise you may have to simplify your SVGs to get them to work.
If you need to display SVGs images that are more complicated than VectorDrawables can handle, then you can always consider using an SVG rendering library for Android. IMHO the best one is AndroidSVG (disclaimer I wrote that one).
There are some cases when your actual .svg file name contains some capital letters. Just rename them in all small letters and try to upload it.
For instance:
If actual .svg image name is mySavedimage.svg {here 'S' is capital which is against norms of android assets}. SO if you rename that file to my_saved_image.svg then this will work as a charm.
hope it helps.
I've never had any luck with those convert sites. You're better off using photo tools to create an SVG. Make sure to follow the SVG guidelines from Android listed here
The error is in the converter. The SVG file might not be proper.
You need to use photo editor tools like Photoshop or Gimp.
I want to create an VectorDrawable from a remote SVG file (ie a URL), within my app (not in Android Studio). After a bit of searching, I have yet to find a way to do this programmatically, is there even a way to do this?
Any help would be appreciated.
First yo need to download the resource like a file or InputStream class type.
After that, you must transform to a graphic class. To do that I found this library: Library tutorial
Good Luck!
Sorry if this is a repeat but I searched diligently and didn't find this question asked yet...
So back in ye olden days of Android, you could just add something like this to a WebView's source html:
<img src='file:///android_res/drawable/my.png'/>
And it would display my.png correctly in the WebView. But-- Android now supports (and prefers we use) these new-fangled vector drawables, and Android Studio's Vector Asset Studio makes it really easy to import them from SVG files or whatever.
The great thing is that for backwards compatibility, .pngs are automatically generated during the build for various dpi/screen sizes to support older devices. So if you're targeting an older device, there are .png images there.
If only I could reach them. Because, as far as I can tell, using vector graphics does break those file:///android_res/drawable/ img links in WebViews. Which is weird, because as I say there are .png files to see, if it only looked.
I've thought about a few methods to fix this, but none have worked:
Since .pngs are generated on-the-fly and are included in the .apk, I thought maybe I could point directly to one of the generated files with something like file:///android_res/drawable-hdpi-v4/my.png. (I checked the .apk file and that's where one of them was..) But no such luck there. Broken image.
Okay, I thought-- maybe there's a way to get the WebView to display the vector objects directly. That is, maybe the WebView would recognize an <img src="file:///android_res/drawable/my_image.xml"/> or something similar. I mean, Chrome can render svg right? Maybe it supports the .xml vector format too. But no dice here either. (Even if it had worked, it would be unlikely to support older pre-chromium webview versions.)
The third thing I tried is to include just one xxxhdpi-sized .png in res/drawable so that the webview would find it and hopefully display it. Unfortunately, this doesn't work either. It appears that just having an .xml vector in /drawable is enough to have it block the png, no matter if it's in the /drawable or /drawable-xxxhdpi directories.
So the obvious question: Is there a way to get the WebView to either display the vector xml (or the associated support .png that was generated)? How do we access drawables from HTML in a WebView w/Vector drawables? Esp. without having to do anything programmatically?
Anyone know how this is supposed to work? I guess the next thing to do is delve into the chromium/android source to try to find out how file:///android_res/drawable/ works, but that doesn't sound fun, so if anyone has an answer, that would be helpful.
I'm probably missing something really obvious here. Thx in advance!
Update: Other things I tried/ruled out include (1) removing underscores in image names (as I thought they might be replaced with "/"), (2) various permutations of baseurl in loadDataWithBaseUrl()
Well, four years later and the best solution I've come up with is just to have two vector files-- (1) the xml Android vector file for the app, and then (2) the identical image in the .svg format for the webview. This is still a smaller solution compared with providing a seperate .png or .gif for every dpi, etc.
SVG and the vector format are internally very similar, so it's not difficult to convert one to the other. In fact, Android Studio will convert SVG->XML. If you want to go the other way, just compare a few examples.
So just put your svgs in assets/svg/, and then you can access from a webview using <img src='file:///android_asset/svg/mysvg.svg'/> in your HTML.
There's still a storage hit. But svgs are relatively tiny (and you can minify-- ie, scoop out some of the extra fluff in the SVG file that isn't used by the webview) so it's not as bad as the alternative-- providing large binary image files in the apk.
New to Android development and have decided to use NetBeans 6.9.1 as my IDE. So far the process has been somewhat painful, but I'm getting things rolling. However, I am creating an ImageView subclass for my first custom View and I can't figure out how to add my Box.png file to the project. Drag and Drop doesn't work, there are no right-click options to add a file to the Resources folder, no dropdown menus to add images, no way to add the image to a package. Could use some insight, thanks!
Just go to the project folder and copy the images you want into the res/drawable folder. The IDE helps you a lot with code completion, error checking, etc... but that simple task can be done by hand.
Then, you can reference your resources by using something like: R.drawable.image Notice that I'm not using the image extension. If you wonder what R is, let me give you a brief explanation:
Each resource that is saved in the resources directory is referenced in the R class. That's a file that is autogenerated by Android and it's used to reference those resources from your code. In this case, it will be in R.drawable.* since it's a drawable resource. There are other kind of resources, like layouts: R.layout.something or strings R.string.whatever. That's essential for the android development, so you better read some tutorials (or buy books) in order for you to get started.
So, in your case will be something like setImageDrawable(R.layout.wood); However, I highly recommend to read first a couple of tutorials. Google about it, you will find tons of them.