Finger Painting/Drawing

Problems with Canvas, OpenGL, etc...

Finger Painting/Drawing

Postby cruiz » Sat Nov 20, 2010 4:56 pm

Can someone please help me...I'm a noob in android programming, I'm still going through tutorials....I'm trying to create simple drawing program. I got it to draw dots but I cant get a constant drawing going. I just want to be able to paint freely using finger touch but when I drag my finger across the screen it just draws dots. I have it set to use canvas.drawCircle...and I know this is the reason why its drawing dots..but I just don't know what else to use.

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. package com.example;
  2.  
  3. import java.util.ArrayList;
  4. import java.util.List;
  5. import android.content.Context;
  6. import android.graphics.Canvas;
  7. import android.graphics.Color;
  8. import android.graphics.Paint;
  9. import android.view.MotionEvent;
  10. import android.view.View;
  11. import android.view.View.OnTouchListener;
  12.  
  13. public class DrawView extends View implements OnTouchListener {
  14.  
  15.  
  16.     List<Point> points = new ArrayList<Point>();
  17.     Paint paint = new Paint();
  18.  
  19.     public DrawView(Context context) {
  20.         super(context);
  21.         setFocusable(true);
  22.         setFocusableInTouchMode(true);
  23.         setBackgroundColor (Color.WHITE);
  24.         this.setOnTouchListener(this);
  25.  
  26.  
  27.         paint.setColor(Color.BLACK);
  28.         paint.setAntiAlias(true);
  29.     }
  30.  
  31.     @Override
  32.     public void onDraw(Canvas canvas) {
  33.         for (Point point : points) {
  34.             canvas.drawCircle(point.x, point.y, 5, paint);
  35.         }
  36.     }
  37.  
  38.     public boolean onTouch(View view, MotionEvent event) {
  39.         Point point = new Point();
  40.         point.x = event.getX();
  41.         point.y = event.getY();
  42.         points.add(point);
  43.         invalidate();
  44.         return true;
  45.     }
  46. }
  47.  
  48. class Point {
  49.     float x, y;
  50.  
  51.     @Override
  52.     public String toString() {
  53.         return x + ", " + y;
  54.     }
  55. }
Parsed in 0.037 seconds, using GeSHi 1.0.8.4
cruiz
Freshman
Freshman
 
Posts: 2
Joined: Sat Nov 20, 2010 4:46 pm

Top

Re: Finger Painting/Drawing

Postby Matt M » Fri Nov 26, 2010 10:07 pm

Copy this class and then edit it to your needs:
http://developer.android.com/resources/ ... Paint.html
User avatar
Matt M
Developer
Developer
 
Posts: 30
Joined: Tue Apr 27, 2010 7:35 pm

Top

Return to Android 2D/3D Graphics - OpenGL Problems

Who is online

Users browsing this forum: No registered users and 2 guests