Posts

Showing posts from January, 2014

Drawing shapes with fingers

Image
It is very simple to draw basic shapes with fingers. As always, it is just an example, you can improve it in many ways. First of all we need a custom View . public class DrawingView extends View { } Then we will use a Bitmap, a Canvas and a Paint ojbects: protected Paint mPaint; protected Bitmap mBitmap; protected Canvas mCanvas; To initialize the bitmap and the canvas, we can override this method in our View: @Override protected void onSizeChanged(int w, int h, int oldw, int oldh) { super.onSizeChanged(w, h, oldw, oldh); mBitmap = Bitmap.createBitmap(w, h, Bitmap.Config.ARGB_8888); mCanvas = new Canvas(mBitmap); } If you need to create a new Canvas, you must define the Bitmap upon which drawing will actually be performed. The Bitmap is always required for a Canvas. Then we can define the paint object. The Paint holds the information about the style and the color which we will use to draw. For example: public