Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • How to make Draw on a Canvas in Android.

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 49
    Comment on it

    How to make Draw on a Canvas in Android. If you want to create Draw on a Canvas function check below example. In the below example I have created a Suraface class. Canvas works like as an interface. I have also used onDraw() method for drawing event.

    Step(1)-MainActivity -

    public class MainActivity extends Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        Suraface v = new Suraface(this);
        setContentView(v);
    
    }
    
    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.main, menu);
        return true;
    }
    }
    

    Step(2)Suraface class-

    public class Suraface extends SurfaceView implements
            SurfaceHolder.Callback {
        Bitmap mBitmap;
    
        public SurafaceClass(Context context) {
            super(context);
            mBitmap = BitmapFactory.decodeResource(getResources(),
                    R.drawable.ic_launcher);
            }
    
        @Override
        public void surfaceChanged(SurfaceHolder holder, int format, int width,
                int height) {
    
        }
    
        @Override
        public void surfaceCreated(SurfaceHolder holder) {
    
        }
    
        @Override
        public void surfaceDestroyed(SurfaceHolder holder) {
    
        }
    
        @Override
        protected void onDraw(Canvas canvas) {
            canvas.drawColor(Color.BLACK);
        }
    
    }
    

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: