webkit raster vs vector images - android

I am trying to address a resolution issue when designing HTML for webkit browsers.
So basically the problem is that webkit browsers can have resolution anywhere from 240x320 to 960x640 and I can't have a separate image/icon set for each one but I do want the pages to look the same on all devices (or very close at least).
Scaling the image (working with percentages) works but it's a performance degrade:
http://code.google.com/speed/page-speed/docs/rendering.html#SpecifyImageDimensions
The other option is using vector graphics which is supported in webkit but I am not aware of the performance implications that is going to have on the pages/app.
The other option is to have a few icon sets for some standard well know resolutions and when you get a browser which is outside of these groups you apply some minor scaling on the set which is closest to the users native resolution.
So basically what I am asking is, what would be the best route to achieve this with performance in mind?
Thanks
-Assaf

Vector graphics are always more expensive in terms of runtime performance as complex equations are run to create them. Having said that, I'm not sure if they're redrawn every frame from scratch, or if the result's cached unless it's in a dirty state.
I'd suggest having a few different icon sets for well known resolutions and applying minor scaling if required.

The first answer is not helpful at all. Vector graphics can be just as small as a PNG, and used right can support transparency and various other good features.
The only problem is if your looking for pixel perfect perfection having some of the images scale up might cause problems.
You can also use illustrator to html5 canvas plugin to export directly to html5 canvas.
For our webkit browsers on row icons, we set a property that doesn't allow webkit to scale the icons for desktop browsers. Or for some of the icons we include a small SVG.
They are well supported and work great. Even better would be to use a free font creation tool and paste your vector graphics from illustrator into a font, so that you could use web-font to simply call up ANY size icon, as simple text. We use this technic.

Related

What is the best way to slice from psd to Android XML

I have a sophisticated design for an Android app and designed using Photoshop.
The app has many drawings and curves which mean I can't use Android Studio to develop it there.
I know there are many ways to slice in Android, but I can't find the best way yet to finish the job quicker and with a higher quality.
The VERY BEST solution - use Zepline online service: https://zeplin.io/ .
It is, this service authomatically calculates all dimensions in 'dp' (you don't have to calculate everything manually)- just select widget and see margins, space between elements, etc. But, the MOST useful thing, is that it converts your pictures into .png files to drawables for ALL densities. It releive you from pain of scanling up and down all pictures.

Should Android app make use of SVG's to maximum extent?

The official documentation Vector Asset Studio states that SVG can be used to reduce APK size. It also states that SVGs take much CPU cycles for drawing.
The initial loading of a vector graphic can cost more CPU cycles than
the corresponding raster image. Afterward, memory use and performance
are similar between the two. We recommend that you limit a vector
image to a maximum of 200 x 200 dp; otherwise, it can take too long to
draw.
Also, it is supported from Lollipop onwards. On backward compatibility, it states that-
Android 4.4 (API level 20) and lower doesn't support vector drawables.
If your minimum API level is set at one of these API levels, you have
two options when using Vector Asset Studio: generate Portable Network
Graphic (PNG) files (the default) or use the Support Library.
For backward-compatibility, Vector Asset Studio generates raster
images of the vector drawable. The vector and raster drawables are
packaged together in the APK.
Raster images look like more efficient than the SVGs. Also, though the size of APK will be reduced, what will be the impact of SVG on memory and app performance as the doc states that it will take time to draw large SVG files.
As an android developer, what should be my approach? Which of above or any other ways will ensure my apps be optimized and deliver good performance.
Edit : A query then, What should be the best approach among the two -
Reduce the apk size by using the SVGs but will increase CPU cycles for drawing
Use raster images
In my own experience Vector Asset Studio is picky about what it accepts in an SVG. If you are not well versed in SVG you are going to have a hard time massaging the SVG markup into something that VAS accepts. From the top of my head I recall it doesn't support defs or filter, but some vector graphics software seems to include it even if it's not strictly necessary. Given flat icons (no gradients or shadows, for example) you can work around this by manually editing the mark-up.
As for performance, it really depends on the amount of icons you will display per screen, and the complexity of these icons. You will have to conduct some stress tests to see if your target devices hold up. Note that this only impacts the initial load, behind the scenes these vector images are rasterized and—as the text you cited mentions: Afterward, memory use and performance are similar between the two.
Your approach should be pragmatic, attempt to draw a couple of your icons on the screen and see how smoothly it goes. This is a subjective question that depends on the constraints of the device and the person who implements it.
My experience using react-native-svg was very good, but animation performance that needs to recompute dynamic SVG suffered from I think they call it 'too many passes over the bridge'. There may be a way to optimise it, and I intend to investigate this on my next RN project. I should qualify this last statement by emphasising that animation only suffers when the SVG needs to be recomputed during the animation (on the JS side). For example have a native ScrollView component with your SVGs inside it, the ScrollView can animate perfectly performantly, but if you want to change the SVGs programatically as a function of scroll position within the React/JS side, you will have the bridge problem, and dropped frames galore.
Here is my boilerplate which sets up a few basic shapes in Android RN:
proto__33__boilerplate
Generally I would say (programmatic) SVGs are great for Android, but I haven't yet found a performant way to use them for animations. Will update if I find that.

Can background images be used with google asset studio

I have some background images that have been designed using Photoshop. I did the same image using Illustrator that uses vector graphics, but when deployed the image did not scale very well. Sometimes too big or small. From experimenting, the photoshop images looked much better, even though it used raster images.
I have set the layout background property to this:
android:background="#drawable/camera"
I have just a few questions:
What is better for creating background images, photoshop (raster) or Illustrator (vector)?
As all smart devices are different dpi's and sizes. Is what recommended size should I create the original image when designing it in photoshop or Illustrator?
I noticed that asset studio can create scalable images but can the icon launcher be used for background images, or is it only for launcher icons?
Android Studio 0.5.4
This depends on what your final image should look like or which
tool is better suited for your needs. PS is more suitable to create
pixel graphics and IL is better used for shapes, buttons and so on. In the
end it doesn't matter for android, because internally graphics are
interpreted as bitmaps and therefore are pixel-based. Android
unfortunately doesn't support SVG by default, although there are libs
available.
You should have a look at the supported screens range
http://developer.android.com/guide/practices/screens_support.html#range
You can't really create background images that fit every screen but at least you can approximate them, so only some parts of the image are cut off eventually. Alternatively you can use 9drawables to stretch an image to fit every screen. In that case you will need an image with stretching marks as described here: http://www.vogella.com/tutorials/AndroidDrawables/article.html#drawables_9patch
Asses Studio is best used for Icons. However you could use it for generating the above mentioned 9drawables in the correct sizes: http://android-ui-utils.googlecode.com/hg/asset-studio/dist/nine-patches.html

Does embedding vector graphics in apps makes sense?

I wonder whether it makes sense to put in my iOS app vector graphics. I wonder whether they could be drawn by system faster or not (from raster - which I can't scale too much - equivalents). Maybe this depends on the complexity of an image ?
Does it makes sense ? To have vector graphics, and don't worry about scaling images between iPad screen and iPhone screen ?
What's the preferred way to embed things like logos, and icons in iOS apps ?

Making a low res image look good

I'm displaying images from various of sources, and can't control the quality I get, I want to display all images in same size and make them look good no matter how small they are.
Is there a filter, magic effect, whatever I can do to the image to make it look good?
You mean fitting a low-resolution image into a large frame size and still look good and sharp? Android doesn't have this magic. Sorry
You could apply a blur effect on your image, which is what most modern browsers and image viewers do nowadays in order not just to show a big block of pixels - not sure what your scenario is though (native or HTML5 app ? Are the images bundled into the app or are you loading online resources?)...
For starters, here's a nice tutorial on different blur techniques incl. java code samples (Found in this post).
The closest thing Android comes with is to use paint.setFilterBitmap(true) for the paint you use to draw the bitmap.

Categories

Resources