Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6885121
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T05:35:43+00:00 2026-05-27T05:35:43+00:00

I am new to android,i prepared one painting view using finger with help of

  • 0

I am new to android,i prepared one painting view using finger with help of FingerPaint.java in Api Demo.It is working fine.

The same view contains one button(clear),if we click on button paint will be clear(empty sceen and one button).My problem is how to clear the paint.My view code is,

public class MyDraw extends View {

    Paint mPaintAlphabet = new Paint();

    private static final float MINP = 0.25f;
    private static final float MAXP = 0.75f;

    float x, y;
    float mX, mY;
    private static final float TOUCH_TOLERANCE = 4;

    private Bitmap mBitmap;
    Canvas mCanvas;
    Path mPath;
    Paint mBitmapPaint;

    public MyDraw(Context context) {
        super(context);

        mBitmap = Bitmap.createBitmap(320, 480, Bitmap.Config.ARGB_8888);
        mCanvas = new Canvas(mBitmap);
        mPath = new Path();
        mBitmapPaint = new Paint(Paint.DITHER_FLAG);


    }

    public MyDraw(Context context, AttributeSet attributeSet) {
        super(context, attributeSet);

        mBitmap = Bitmap.createBitmap(480, 480, Bitmap.Config.ARGB_8888);
        mCanvas = new Canvas(mBitmap);
        mPath = new Path();
        mBitmapPaint = new Paint(Paint.DITHER_FLAG);

        mPaintAlphabet.setDither(true);
        mPaintAlphabet.setColor(0xFFFF0000);
        mPaintAlphabet.setStyle(Paint.Style.STROKE);
        mPaintAlphabet.setStrokeJoin(Paint.Join.ROUND);
        mPaintAlphabet.setStrokeCap(Paint.Cap.ROUND);
        mPaintAlphabet.setStrokeWidth(3);
        mPaintAlphabet.setTextSize(350);

    }

    protected void onSizeChanged(int w, int h, int oldw, int oldh) {
        super.onSizeChanged(w, h, oldw, oldh);
    }

    public void onDraw(Canvas canvas) {

            if (MyAlphabetsActivity.mArryLstAlphabets.get(
                MyAlphabetsActivity.mAlphaIndex).equals("I")) {

            canvas.drawText((String) MyAlphabetsActivity.mArryLstAlphabets
                    .get(MyAlphabetsActivity.mAlphaIndex), 180, 300,
                    mPaintAlphabet);

        } else if (MyAlphabetsActivity.mArryLstAlphabets.get(
                MyAlphabetsActivity.mAlphaIndex).equals("J")) {

            canvas.drawText((String) MyAlphabetsActivity.mArryLstAlphabets
                    .get(MyAlphabetsActivity.mAlphaIndex), 180, 300,
                    mPaintAlphabet);

        } else {
            canvas.drawText((String) MyAlphabetsActivity.mArryLstAlphabets
                    .get(MyAlphabetsActivity.mAlphaIndex), 120, 300,
                    mPaintAlphabet);
        }

        System.out.println("in on draw");
        System.out.println("path is----" + mPath);

        canvas.drawBitmap(mBitmap, 0, 0, mBitmapPaint);

        canvas.drawPath(mPath, MyAlphabetsActivity.mPaint);
    }

    private void touch_start(float x, float y) {
        mPath.reset();
        System.out.println("mPath-----"+mPath);
        mPath.moveTo(x, y);
        mX = x;
        mY = y;
    }

    private void touch_move(float x, float y) {
        float dx = Math.abs(x - mX);
        float dy = Math.abs(y - mY);
        if (dx >= TOUCH_TOLERANCE || dy >= TOUCH_TOLERANCE) {
            mPath.quadTo(mX, mY, (x + mX) / 2, (y + mY) / 2);
            mX = x;
            mY = y;
        }
    }

    private void touch_up() {
        mPath.lineTo(mX, mY);
        // commit the path to our offscreen
        mCanvas.drawPath(mPath, MyAlphabetsActivity.mPaint);
        // kill this so we don't double draw
        mPath.reset();
    }

    @Override
    public boolean onTouchEvent(MotionEvent event) {
        x = event.getX();
        y = event.getY();

        switch (event.getAction()) {
        case MotionEvent.ACTION_DOWN:
            touch_start(x, y);
            invalidate();
            break;
        case MotionEvent.ACTION_MOVE:
            touch_move(x, y);
            invalidate();
            break;
        case MotionEvent.ACTION_UP:
            touch_up();
            invalidate();
            break;
        }
        return true;
    }


}

And my Activity code is,

public class MyAnimViewActivity extends Activity
         {    
    public static Paint       mPaint;
    private MaskFilter  mEmboss;
    private MaskFilter  mBlur;
    Button mBtnClear;
    MyDraw mMyDraw=new MyDraw();
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(new MyOwnView(this));

        mPaint = new Paint();
        mPaint.setAntiAlias(true);
        mPaint.setDither(true);
        mPaint.setColor(0xFFFF0000);
        mPaint.setStyle(Paint.Style.STROKE);
        mPaint.setStrokeJoin(Paint.Join.ROUND);
        mPaint.setStrokeCap(Paint.Cap.ROUND);
        mPaint.setStrokeWidth(12);

        mEmboss = new EmbossMaskFilter(new float[] { 1, 1, 1 },
                                       0.4f, 6, 3.5f);

        mBlur = new BlurMaskFilter(8, BlurMaskFilter.Blur.NORMAL);

        mBtnClear=(Button)findViewById(R.id.btnClear);

        mBtnClear.setOnClickListener(new OnClickListener() {

            public void onClick(View v) {
                // TODO Auto-generated method stub
                switch (v.getId()) {
                case R.id.btnClear:
                    mMyDraw.mPath.reset();

                    break;

                }
            }
        });
    }
}

Please help me..Thanks in advance

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T05:35:43+00:00Added an answer on May 27, 2026 at 5:35 am

    make a public function in your custom drawing class named as clearDrawing(); and write this:

    mBitmap = null;
    mPath = null;
    mBitmap = Bitmap.createBitmap(480, 480, Bitmap.Config.ARGB_8888);
    mPath = new Path();
    

    now call clearDrawing() to reset drawing control.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am new to android.i am prepared one app, it support multiple languages.I want
i have prepared one custom view using onDraw method, my view class is, public
EDIT: Android 2.2 MediaPlayer is working fine with one SHOUTcast URL but not with
i am creating a new android application.i am using the table layout. I have
I just created a new android project and prepared the basic structure for it.
Hi i'm new android. i'm working through the samples and have an error when
i have prepared paint application,my application contains one custom view for paint.when we draw
I'm trying to record audio this.recorder = new android.media.MediaRecorder(); this.recorder.setAudioSource(android.media.MediaRecorder.AudioSource.MIC); this.recorder.setOutputFormat(android.media.MediaRecorder.OutputFormat.DEFAULT); this.recorder.setAudioEncoder(android.media.MediaRecorder.AudioEncoder.DEFAULT); this.recorder.setOutputFile(pruebaAudioRecorder.mp4); **this.recorder.prepare();**
The new Android 2.1 SDK (version 7) has a new class called SignalStrength: http://developer.android.com/reference/android/telephony/SignalStrength.html
I just installed the new Android SDK and the ADT 17. After the Installation

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.