Hasan Bou Taam
Hasan Bou Taam

Reputation: 4035

Android canvas is it possible to draw using vector data

The most common way to draw with your finger on screen is to use android's built in canvas, the usual steps are:

1) Create a custom view (drawing view).

2) Set a bitmap to the canvas.

3) initialize a path (set paint, ...).

4) implement onTouchEvent (DOWN/UP/MOVE) to get position points (X && Y).

5) call onDraw() to draw each path according to the X && Y.

so my data here is X && Y (the finger position on screen).

Problem

Some note apps, use a special technique called (drawing with vectors), at first I didn't get the idea (because all I know is canvas and the old way of finger drawing).

After research

I researched a bit and found out that vectors are graphics that scale without losing quality.

I found out a similar post to my problem this one.

If you opened the link and read the answer you will see that @Trevor stated a very good answer on that. He said that you must get the path data using your finger and store them as vector data in memory.

Store them as vector data in memory??

Okay what is that supposed to mean, where should I store them and what is the format knowing that I only can use the finger to get two float positions X && Y...so how I save them as vector? and where should I save them?

If I was able to save them

How to retrieve them and draw them back using canvas onDraw() method?

Do you think this is the meaning of drawing with vectors? If yes, What is the purpose?

I am looking at a way to enhance drawing technique on canvas and manipulate the drawings to make them feel more realistic.

Thanks for your help.

Upvotes: 2

Views: 2201

Answers (1)

Tau
Tau

Reputation: 632

Scalable Vector Graphics (.svg) is a simple file format based in HTML. You would probaly generate a .svg element on the fly from user inputs, which you can then draw to the screen again (with appropriate libraries) and also can save / reload into your application very easily.

Here is a tutorial on svg paths, which sounds like what you would want; Bézier curves make for a good interpolation between your data points.

Upvotes: 1

Related Questions