I would like to draw technical illustrations in my Android app.
I have images with shapes, and I have to change the size of those shapes based on input data. Thought that I could save those images as SVG, then I could manipulate the size of the shapes in it. For example, I would like to take a with a specified ID, and change its width/height.
There're great SVG display libraries for Android, but I haven't found one which can also manipulate the graphics.
Do you know any library which can do this?
If not, how else should I draw my illustrations?
Related
Question from a beginner) Why do I get stripes between color transitions when converting an image to SVG and uploading it to android studio? How to fix it ?enter image description here
enter image description here
The SVG image format can only represent things in vectors, meaning lines or curves, as opposed to the usual pixel-based formats.
This means it is very efficient for representing diagrams, simple shapes and letters, to the point where you can zoom endlessly into them without losing quality, but it cannot represent full-color realistic images with the same precision or efficiency.
Basically, you should only use SVG (and other vector-based graphics formats) for icons and simple shapes, not complex shapes with different hues of color.
I'm new to Android development. I have a library here that produces LCD images that come from a device through USB. These images are small, 120x80 pixel, and are 1-bit. I want to show these images on the UI.
All documents I've found explain how to show bitmaps from image files (PNG etc.) or how to show them from an app's resources. I did find out that I can add an ImageView to the UI. Then, for each incoming 120x80 pixel image, create a Bitmap instance, fill it with pixels, and assign it to the ImageView. However, I do not know if this yields the best performance here.
It is also important to keep in mind that nearest neighbor scaling must be used here. Bilinear filtering with such a small image produces a result that is too blurry.
From my experience with other languages, it seems wasteful to create a Bitmap instance for each incoming image. But perhaps I am wrong here.
Suggestions?
I would like to know what the pros and cons of using drawable vector shapes (XML files) vs image resources (png files) for icons (Material Design Icons)?
As I see, the question refers to general alternative between raster (e.g. jpeg, png) and vector (e.g. eps image). In one sentence, vector can be easily scaled and required less memory, but is more complicated. In details, see e.g. here.
The difference stands in vector images describing what they want to draw and raster images describing the color of each pixel, due to which these are heavier in size.
Vector images can be resized flawlessly, while attempting it on raster images is always a bad idea, which makes those images lose their quality.
Moreover, vector images are rendered slower than raster ones when there are many elements, due to the computations necessary to parse paths and shapes and draw them (indeed, vector images are more CPU intensive to render). Rather, it is faster if there are just few elements and paths have few points. Though vector images are lighter to load (in RAM; in fact they cannot be loaded in the GPU memory, unlike raster images), which makes them the fastest.
The important is, don't exceed with the number of elements in SVGs and other vector images. Otherwise, they'd end up being slower.
It depends on your needs to use which one. you can change vectors attributes with xml code anywhere you want. but image resources has less Flexibility to control its attrs and use more memory
VectorDrawable is a new feature for Android after API Level 21, Which add support for vectorgraph. But I have a question for VectorDrawable, is it suitable for me to replace most of images in my project to VectorDrawable. In the android offical dev site I saw a few words :
A vector drawable is appropriate for simple icons. The material icons provide good examples of the types of images that work well as vector drawables in an app. In contrast, many app launch icons do have many details, so they work better as raster images.
Is that means VectorDrawable is only appropriate for simple icons like offical material icons, images have many details aren't appropriate to use VectorDrawable.
Sorry for my poor english skills, hope you guys can understand me! 😬
I plan to use VectorDrawable for all my project image resource if it is ok.
You're basically right.
Vector images describe shapes and geometry, and need to be rendered into bitmaps (a grid of pixels). This requires some math, calculating the pixels that represent the lines and curves defined by the icon.
The more complicated an icon gets, means the more shapes that are required, and the more calculations that need to be done.
On the other side, if you already have the icon rendered to a specific scale, like with png images, all of the pixel values have already been calculated. Now it just needs to be converted to a bitmap and scaled to the size it gets displayed at.
So depending on the situation, an icon may be able to decode and scale from a png file faster than rendering from a vector drawable, or vice versa, it all depends on the icon.
It's hard to say exactly how simple an icon needs to be, so try it out and make sure it runs well on a range of devices.
Is it possible in Android to use the Vector images (for example, contours made in Adobe Illustrator) to be drawn on Canvas?
I looked at Vector graphics in Android but I don't want to use any additional third-party libraries.
So, is there any another way to make this idea?
One thought, that came to mind, was to convert to the 9patch images. But still I'm not sure whether it sounds good.
All of fuss just over the aim to make the complex countour from which I want to create android.graphics.Path using public void addPath (Path src, Matrix matrix) function.
You cannot use vector images in Android, at least with the built in SDK.
It may exist libraries to use vector images, but this is not the Android best practice.
What you need to do in order of not pixelating/blurring your images is to use the different drawable folders existing in android.
You should provide different images depending on the screen density of the display, and android will pick the correct one in runtime.
http://developer.android.com/guide/practices/screens_support.html
9 patches are good only if the image is meant to stretch to fit its content, while its borders should repeat following a pattern. The typical use of this are buttons. For images that dont work as the background of a View, 9 patches are not a good option.