Optimal PNG images for Android - android

A long time ago I came across a video from one of the Android developers giving an introductory lecture about Android. At one point during the lecture he mentions that Android is optimized for specifically formatted PNGs. I can't find the video or any reference to the formatting. Does anyone know?

Are you referring to android .9 PNG's? if so here is a link
Android PNG
.9 PNG for Themes youtube video
hope that helps

I didn't find the video, but I did find this.
http://developer.android.com/guide/topics/graphics/2d-graphics.html#drawables-from-images
Taken from the first line:
Supported file types are PNG (preferred), JPG (acceptable) and GIF (discouraged).
Furthermore, if you look a little bit down, it goes into detail about NinePatchDrawable graphics, which are expandable PNG files and would explain why Android prefers PNG files to any other kind.

You could take a look at these slides, which I felt were very helpful and a must-see for many intermediate Android developers. Although he doesn't talk exactly about what you are asking, it may still be helpful.

I've found the video and the formatting I was referring to in the OP:
The format is 565 formatted PNGs. The reference is at 0:04:17 here: http://www.youtube.com/watch?v=7zKy9iInXkY
It should be noted that this video is quite old. I cannot find any references to the 565 formatting in the current Android documentation. Formatting PNGs in 565 may be unnecessary now.

You can optimize png file size using OptiPng tool (find using search). And it appears that RGB565 mode is drawn faster than ARGB8888 when you use Canvas. See here: http://www.rbgrn.net/content/286-how-to-test-android-performance-using-fps. And png could be transparent :) That's all I know.

Related

Android: How to load a vector drawable image into a webview?

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.

Displaying SVG files in Android

I want to create an app that will display position on some floor plan. Navigation is implementing via WiFi in certain way, I've done it and so now I have a problem of displaying floor plan.
It might be in some vector format, after surfing internet for some time I've decided that it must be svg file.
I found some solutions, but it isn't working for me!
Library svg-android
There is opportunity to display .svg files, but only "simple" files. It works fine only for file in tutorial, but not for any other .svg file (for example, some other file, that you'll create with Inkscape).
So, I decided, that I'll parse .svg file, make DOM from it, somehow get objects and attributes and draw it via OpenGL ES.
Apache Batik
At first glance, very good solution, but there is a problem. Android has some "native" apache libraries and when I try to do something with batik, it throws NoClassDefFoundError, because it's searching not in batik libraries, but in "native" libraries.
Of course, we can add source code in our project, take only batik parser for .svg files and edit it in some way, but there is a lot of work, with same success we can write our own parser.
Tiny Line
There is no trial version, but if we'll see description of how it works for svg files and android, we'll see that there is only rasterization of such files and that's all.
Is there any solution better than writing own parser?
Did anyone come across this problem?
I would suggest using #1. Don't write your own parser. It's just going to be a huge headache.
How detailed does your floor plan have to be? android-svg supports SVG fairly well. It just doesn't have great support for filters or light sources. Your SVG isn't going to have those in them (I hope).
If you don't want to do that, look into quad trees. You can render out a huge image and break that down into a quadtree like format then only load the quads you require.
I have authored an SVG libaray for android the website is
http://www.vectoroid.com
the main thing missing is SVG arc support this is currently fixed and will be in a release in the near future.
I am looking for feedback on it, as i have been working on it for about a year. So if you have any please do tell ...
I've using yet another SVG for Android; seems it is relatively new.
GPLv3, CSS2 support, fonts, texts and spans, linear and radial gradients, SVG and SVGZ, initial filtering support, images from assets, from web and inline base64-encoded images. Fastest from all I've tried.
Of course filters support might be better, but except this it works well and even displays 20-megabytes SVG files.
Successfully tested these 2 libraries:
https://github.com/BigBadaboom/androidsvg - Apache License 2.0
https://scand.com/products/svgkit-android/ - needed tweaking to compile with modern SDK (suppress warnings, update gradle file); LGPL / commercial
androidsvg looks better so far.

Android game Image format

I have a problem with an image for an android game. The problem is not a problem with the code because the code that I use I took from a book (Beginning Android 4 Games Developer).
The problem is this: I know the format that I have to use in android: png, but I don't know the settings for this format that I have to use (like RGB565...). Because if I use simply png, when I run the game the images are not good. So I need someone to explain to which settings I need to use for images for android games.
P.S The software that I used is photoshop. If there is better software for this purpose tell me.
I think there is a strong misconception in your understanding of Android and how it implements graphics. You are not constrained to .png for nearly any of your development. The .png and .9.png are only enforced strictly for managing drawable constants.
Android uses Java and has the capability to utilize nearly any graphical format. In particular native support for .bmp, .png, and .jpg are present for every device and Android OS version. You may even create your graphics in realtime byte by byte.
As for a good image editor, there are a number out there. I often use a combination of GIMP and Photoshop, myself.
Hope this helps,
FuzzicalLogic

Where to download a vector file of Google's green android robot?

Does anyone know where to download a vector file of Google's green android robot?
The Android Brand Guidelines page does not have a link to it!
Thankyou, Mel
http://www.android.com/media/wallpaper/eps/android_logo.ps
more: http://www.android.com/media/
This question is rather old, but I had the same question.
The vectors I found weren't up to my standards (overlapping shapes, ungrouped paths, etc.) and they were mostly postscripts. You probably need an Illustrator file or SVG. I made a new one from a postscript version on the Android site. You can download the updated .ai or .svg here:
http://bit.ly/android_vector

Android NinePatch .png file format?

Android NinePatch images seem to be standard .png files with extra information. Is there a spec for the format anywhere, as I'd like to be able to implement this on other platforms?
This is the most straightforward link I've found on the subject.
Just take a look at a 9 patch image in an image viewer. It's simply just a 1px border with black pixels flanking the stretchable areas and transparent marking the static parts.
If you zoom into this image you can see the black border marking the stretchable area:
example http://web6.twitpic.com/img/91916457-a53b6866db73378bda07c039151c69aa.4bd6119a-full.png
I would strongly suggest that you not implement the 9patch system on other platforms, for several reasons.
I have been using Android's developer tools for a year and have made extensive use of 9patch files.
They are a nightmare. PNG is not a data format, it is an image format. Mixing the two in the .9.png file is asking for trouble.
9patch files are a poor idea because they combine image and data formats into a single file that is neither fully manageable by a designer nor a developer.
Nine patch files: you will regret your involvement at some point during maintenance, support and updates phase.
Perhaps if at some future date support for 9patch files is added to a number of quality tools (for example, PS CS4 doesn't understand 9patch files as a specific format, nor does it honor the rules of valid nine patch formats.)
The existing tools for nine patch files are awful -- essentially unusable in the opinion of most designers who I have hired.
This Link is very useful for nine patch image in android.
It is very useful example in android. Only use .9 patch PNG file.
http://blogingtutorials.blogspot.com/2010/12/android-nine-patch-example.html
Modern browsers support CSS 9-path based backgrounds:
http://www.css3.info/preview/border-image/
I found this link to be very useful: link to blog post. It uses some examples for the different borders defined when a 9 patch is created. It shows how the extra information is used in scaling the images' dimensions (x,y).
There is even a nice comment by a Richard L. at the end which says how you can add regions to be protected from scaling the image by including breaks in the borders; eg. not scaling sections in the image.
Took me a while to understand that the Extension of the 9 patch file should be xxxx.9
and not xxx.9.png

Categories

Resources