Generate of all drawable sizes from one (large) image automatcly - android

I am investing some time doing drawables for an Android project and I am looking for alternatives.
Currently I do them on Adobe Illustrator and with some drawables I can use Android Asset Studio (e.g. drawables for the action menu). The problem with Android Asset Studio is the lack of possibilities to use my own color (we can only use white/black colors).
I wanted something like Android Asset Studio where I can give him a HD image and he creates all drawable sizes. Is that possible?
Another option could be a program/script that could allow me to say "I want to scale to these resolutions" and he does it for all images.

What you're looking for is called a batch resizer, but without knowing what you're working with, it's hard to give a recommendation. For instance, you can use both Photoshop and Gimp for it. I believe Gimp will require a plugin, while Photoshop has the script built-in.

Related

Add all sizes of image asset in Android Studio with a PDF or Vector file

In iOS development with Xcode it is really convenient because you can add an image asset or launcher icon with one .pdf file and it generates all the necessary sizes automatically. The .pdf file can be created with Adobe Illustrator or a similar program that makes vector graphics.
Rather than sit there and export every size of icon/image asset one at a time, is there a fast way to add a vector image to Android Studio and have it populate all of the relevant sized folders on its own? Or in general, is there a way to accomplish the same thing in some way?
I have seen other posts where people suggest using an online tool that takes your .png image and lets you download a .zip with all of the different image sizes, but by definition, that method will not result in crisp and high quality image assets. You always want to go from a vector.
is there a fast way to add a vector image to Android Studio and have it populate all of the relevant sized folders on its own?
Use File > New > Vector Asset in Android Studio 1.5 and higher. This will let you import an SVG file. Android Studio will attempt to convert it into a vector drawable resource, with varying degrees of success. If you are using a recent version of the Android Plugin for Gradle (1.5.0 or higher should work AFAIK), the build tools will also generate PNGs from the vector drawables for use on older devices (Android 4.4 and earlier).
but by definition, that method will not result in crisp and high quality image assets
You do not have much of a choice on older devices. There are a few deprecated backports of VectorDrawable floating around that you can try to use, but Google abandoned theirs.
You always want to go from a vector.
Not necessarily. Please bear in mind that not everybody has high-end mobile devices. Rendering SVG or other vector artwork is comparatively expensive, which is why Android did not directly support it (and still does not directly support SVG itself).

Newer versions of Android Studio add only two drawable directories - drawable and drawable-v21

With older versions of Android Studio, all of the drawable bucket folders were created by default (i.e. drawable-mdpi, drawable-hdpi, etc.). In newer versions of Android Studio, it only provides drawable and drawable-v21. Why is that?
Is there a reason that Android (in its infinite wisdom) no longer gives you the separate bucket folders?
Just to note, I know you can just add them manually, but I want to make sure there isn't some new best practice reason to not use those folders anymore.
Thank you to everyone who tried to help. You helped me reach the final answer, but no one solution was quite right. #user3137702 was probably the closest, as it IS related to the whole move to vectors/SVGs. I couldn't find a definitive answer, like something directly from Google (although I imagine it is out there), but from what I've gathered from a bunch of articles, there is probably a reason they are doing this.
For starters, it looks like this started in Android Studio 1.4. I am in 1.5 right now. It seems that Android is moving in the direction of no longer needing you to create your own density folders (i.e. mdpi, hdpi, etc.) for drawables (mipmaps is different, so please don't confuse that with what I am talking about). As of Android Studio 1.4, it will take the SVGs you put in the regular drawable folder (as in not the v21 folder), convert them to PNGs, and place them in auto-generated density folders for you during the build sequence (so Gradle does this for you, essentially) for all versions older than API 21. For 21 and up, SVG is supported different, which is a whole other topic. But this essentially makes SVG support backwards compatible all the way to API 1!!!
HOWEVER, there is a BIG catch. This SVG conversion is not always as successful as you might hope. It only supports a subset of SVG files, so depending on how you save it (i.e. what settings are applied when saving), it may not render properly. Even commonly used settings, such as gradient and pattern fills, local IRI references, and transformations are NOT supported (yet). If you are working with SVG files that you didn't generate, you will likely have problems importing them. If you or someone you work with directly generates them, you may have to experiment with how you save the files, and you should test builds often on older versions of Android to make sure it turned out as expected.
To import SVGs into Android Studio 1.4+, follow these simple steps:
Right-click on the res/drawable folder
Select "New"
Select "Vector Asset"
At this point, you can select a "Material Icon", which works
really well, and there are a bunch of beautiful "free" icons you can
select from. For indie developers, without icon design support,
this is nice!
OR - you can select "Local SVG File"
Then choose an SVG from either option with the "choose" option. WARNING: This is where it could possibly go wrong, if the SVG you import isn't saved properly.
Hit "Next"
Verify it is saving in the right place, and then Click "Finish"
At this point, it is reference-able with: android:icon="#drawable/ic_imagename" (using your image name instead of ic_imagename, of course)
#CommonsWare's response was very helpful in leading to the right solution, but from what I saw, generating several variations of new projects from different template and version support settings, there wasn't any way to actually have the old density folders get auto-generated. There is definitely more going on here than just a different template-version selection. But as he said, depending on what template/version you select, you may end up with a different set of those two drawable folder types. But specific to my question, Android Studio does seem to be putting an emphasis on this new approach of not creating your own individual drawable density folders at all.
It's pretty cool, imo, but it still needs some work. In practical terms, I will likely still need to add the drawable density folders to support all the images I work with, until this mechanism gets a little more supportive of all types of SVG renderings.
And one more tidbit - Because this is all handled through Gradle (the actual generation of the density folders) you can add build settings through the flavor mechanism to limit which density folders you want to generate. So if, for example, you feel mdpi images have reached the end of their usefulness for your particular user base and would like to leave that size/density out of your app to shave a couple MB off the app size, you can set that in the Gradle build flavor.

Is there a program to create icon resources or all resolutions from vector image for android?

I mean for example the app icon. I have a icon in vector format. And now I need to create png images for all kinds of dpi. I don't want to do it by hand. I suppose that there should a program for that, because it's easy to automate this task. But I can't find one.
Recent Android Studio v14 does generate raster images for older android versions than lollipop.

Android 9-patch batch

I am using the Android 9-patch tool to generate my 9-patch images. I have to support a number of different resolutions and button states. This means that for a single 9-patch button I need to generate 16 separate assets. Currently I am generating each of these separately using the Android 9-patch tool interface which is taking a lot of my time. If I was able to specify the 9-patch dot for a range of buttons which have the same properties this would save me a lot of time. Is there the equivalent of a command line tool or other approach which would help.
Thanks
Here is a nifty looking tool I just found. I cannot verify its accuracy or stability, but it claims to do what you want.
You can try to use the Android Asset Studio at http://android-ui-utils.googlecode.com/hg/asset-studio/dist/nine-patches.html.
Well, there's is no tool as you like afair, but you could easily craft small script (PHP, Perl whatever) that would combine two images (main image + 9-patch dots) together. Or you can save dots separately and then load it into GIMP or Photoshop as layers and export as single final 9patch PNG.

Does android have *native* support SVG image as drawable resources (icons)?

I'm reading and watching UI tutorial. They all talk about the fact that you need to be aware of different devices size and resolution. Therefore export your icons into several size to support different screen density.
SVG is an open standard (W3C) that should be use to tackle this kind of problem. So can I natively use SVG file as drawable for my icons ?
N.B.: I'm NOT talking about browser support.
Android does not support SVG rasterization. Look at libsvg-android or svg4mobile. It solves that problem.
The answer has changed. Since version 21, Lollipop the operating system has had support for VectorDrawable. This is added to by a support library that allows you to use VectorDrawable well back into previous versions. These include support for importing most of the important SVG vector commands and having Android Studio automatically convert them to a VectorDrawable.
Use Vector Image Assets for all versions. -- Also even in older versions it's entirely possible to do fonts. Basically you give it a font asset then load up a specific letter of the font as an icon. Since fonts are glyphs and vector glyphs at that, you can very much get vector icons pretty far back.
https://fortawesome.github.io/Font-Awesome/icons/

Categories

Resources