View on GitHub

Bearded-android-docs

Drawing

Download this project as a .zip file Download this project as a tar.gz file

Created Tuesday 10 September 2013

Draw to a View

TODO

Draw to a Canvas

To draw something, you need 4 basic components:

  1. A Bitmap to hold the pixels,
  2. a Canvas to host the draw calls (writing into the bitmap),
  3. a drawing primitive (e.g. Rect, Path, text, Bitmap), and
  4. a paint (to describe the colors and styles for the drawing).

Ex:

private Bitmap getBitmapWithBorder(View v) {
        Bitmap bitmap = getBitmapFromView(v);
        Canvas can = new Canvas(bitmap);

        Rect rect = new Rect(0, 0, bitmap.getWidth(), bitmap.getHeight());

        Paint paint = new Paint();
        paint.setStyle(Paint.Style.STROKE);
        paint.setStrokeWidth(LINE_THICKNESS);
        paint.setColor(Color.BLACK);

        can.drawBitmap(bitmap, 0, 0, null);
        can.drawRect(rect, paint);

        return bitmap;
    }

Links


No backlinks to this page.
comments powered by Disqus