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 7711235
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T01:19:27+00:00 2026-06-01T01:19:27+00:00

I am trying to create a BUTTON over BITMAP or OVERLAYING buttons on the

  • 0

I am trying to create a BUTTON over BITMAP or OVERLAYING buttons on the view. I am creating digital signature here. After signature I need to save for that I need a button.

Here my code

import android.content.Context;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.Bitmap.Config;
import android.graphics.BitmapFactory;
import android.graphics.BlurMaskFilter;
import android.graphics.BlurMaskFilter.Blur;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Path;
import android.graphics.PorterDuff.Mode;
import android.graphics.PorterDuffXfermode;
import android.os.Bundle;
import android.util.Log;
import android.view.MenuItem;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup.LayoutParams;
import android.widget.Button;
import android.widget.TextView;

 public class FingerPaint extends GraphicsActivity
   implements OnClickListener {  
private TextView pauseButton;

protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(new MyView(this));

    Capture_SignatureActivity.writeLog("In FingerPaint class");
    mPaint = new Paint();
    mPaint.setAntiAlias(true);
    mPaint.setDither(true);
    mPaint.setColor(0xFF003F87);
    mPaint.setStyle(Paint.Style.STROKE);
    mPaint.setStrokeJoin(Paint.Join.ROUND);
    mPaint.setStrokeCap(Paint.Cap.ROUND);
    mPaint.setStrokeWidth(1); 

} 
private Paint mPaint;

public void colorChanged(int color) {
    Capture_SignatureActivity.writeLog("In color changed");
    mPaint.setColor(color);
}

public class MyView extends View{
    private static final float MINP = 0.25f;
    private static final float MAXP = 0.75f;

    private Bitmap  mBitmap;
    private Canvas  mCanvas;
    private Path    mPath;
    private Paint   mBitmapPaint;
    private Bitmap overlayDefault;
    private Bitmap overlay;
    private Canvas c2;
    private Paint pTouch;
    private float X =  -100;
    private float Y =  -100;



    public MyView(Context c) {
        super(c);
        Capture_SignatureActivity.writeLog("In MyVIEW");
        mPath = new Path();
        mBitmapPaint = new Paint(Paint.DITHER_FLAG);  


        mBitmap =      BitmapFactory.decodeResource(getResources(),R.drawable.ic_launcher);
        overlayDefault = BitmapFactory.decodeResource(getResources(),R.drawable.ic_launcher);
        overlay = BitmapFactory.decodeResource(getResources(),R.drawable.ic_launcher).copy(Config.ARGB_8888, true);  
        c2 = new Canvas(overlay);         



        pTouch = new Paint(Paint.ANTI_ALIAS_FLAG);         
        pTouch.setXfermode(new PorterDuffXfermode(Mode.SRC_OUT)); 
        pTouch.setColor(Color.TRANSPARENT);
        pTouch.setMaskFilter(new BlurMaskFilter(15, Blur.NORMAL));
        pTouch.setMaskFilter(startActivity(FingerPaint.this, Capture_SignatureActivity.class));



    }

    @Override
    protected void onSizeChanged(int w, int h, int oldw, int oldh) {
        super.onSizeChanged(w, h, oldw, oldh);
        System.out.println("w-->"+w+"-->"+"h--"+h+"-->"+"oldw-->"+oldh+"oldw-->"+oldw);
        Capture_SignatureActivity.writeLog("In  onSizeChanged");
        mBitmap = Bitmap.createBitmap(w, h, Bitmap.Config.ARGB_8888);            
        mCanvas = new Canvas(mBitmap);       
    }

    @Override
    protected void onDraw(Canvas canvas) {
        Capture_SignatureActivity.writeLog("In onDraw");
        canvas.drawColor(0xFFFFFFFF);       

        canvas.drawBitmap(mBitmap, 0, 0, mBitmapPaint);
        canvas.drawPath(mPath, mPaint);

        c2.drawBitmap(overlayDefault, 0, 0, null); //exclude this line to show all as you draw
        c2.drawCircle(X , Y , 80, pTouch);
        //draw the overlay over the background  
        canvas.drawBitmap(overlay, 0, 0, null);

    }

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

    private void touch_start(float x, float y) {
        Capture_SignatureActivity.writeLog("In  touch_start");
        mPath.reset();
        mPath.moveTo(x, y);
        mX = x;
        mY = y;
        System.out.println("---- " +mX);
    }
    private void touch_move(float x, float y) {
        Capture_SignatureActivity.writeLog("In  touch_Move");
        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() {
        Capture_SignatureActivity.writeLog("In touch_up");
        mPath.lineTo(mX, mY);
        // commit the path to our offscreen
        mCanvas.drawPath(mPath, mPaint);
        // kill this so we don't double draw
        mPath.reset();
    }

    @Override
    public boolean onTouchEvent(MotionEvent event) {
        Capture_SignatureActivity.writeLog("In  touch_event");
        float x = event.getX();
        float 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;
    }

    public void onClick(View v) {
        //In myView

        startActivity(new Intent(FingerPaint.this, Capture_SignatureActivity.class));


    }
}

public void onClick(View v) {
    //onCreate

}

@Override
public boolean onCreateOptionsMenu(android.view.Menu menu) 
{
    super.onCreateOptionsMenu(menu);

    menu.add(0, 1, 0 , "Clear Screen");
    menu.add(0, 2, 0 , "Exit Screen");

    return true;
} 

@Override
public boolean onMenuItemSelected(int featureId, MenuItem item)
{
    switch(item.getItemId()) 
    {
    case 1: 
        startActivity(new Intent(this, FingerPaint.class));
        break; 
    case 2: 
        startActivity(new Intent(this, Capture_SignatureActivity.class));
        break; 

    }
    return super.onMenuItemSelected(featureId, item);
}


}

I am able to create image and can’t start activity.

  • 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-06-01T01:19:29+00:00Added an answer on June 1, 2026 at 1:19 am

    Here I got the way to create dynamically buttons on BITMAP & CANVAS

    public class MainAct extends GrapActivity implements OnClickListener {
    
    
    private Button saveButton;
    private Button clearButton;
    
    // onCreate Activity
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);          
    
        // content view 
        signature = new MyView(this); 
    
        // Dynamically created button on bitmap & canvas
    
        RelativeLayout myLayout = new RelativeLayout(this);        
        myLayout.setLayoutParams(new RelativeLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT)); 
    
        // For Save Button
        saveButton = new Button(this); 
        saveButton.setText("Save"); 
        saveButton.setOnClickListener(this); 
    
        // For Clear Button
        clearButton = new Button(this); 
        clearButton.setText("Clear"); 
        clearButton.setOnClickListener(this); 
    
        myLayout.addView(signature); 
        myLayout.addView(saveButton); 
        myLayout.addView(clearButton); 
    
        RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(100, LayoutParams.WRAP_CONTENT); 
        //Alignments
        params.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM); 
        params.addRule(RelativeLayout.ALIGN_PARENT_LEFT); 
        saveButton.setLayoutParams(params); 
    
        //Alignments
        RelativeLayout.LayoutParams params2 = new RelativeLayout.LayoutParams(100, LayoutParams.WRAP_CONTENT); 
        params2.addRule(RelativeLayout.ALIGN_PARENT_RIGHT); 
        params2.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM); 
        clearButton.setLayoutParams(params2); 
    
        saveButton.bringToFront(); 
        clearButton.bringToFront(); 
        this.setContentView(myLayout); 
        new Thread(new RefreshRunner()).start(); 
    
        // onclick listner for CLEAR button
        clearButton.setOnClickListener(new OnClickListener() {          
            public void onClick(View v) {
                //Activity for Clearing the Screen
                startActivity(new Intent(ThisAct.this, ThisAct.class));
                finish();
            }
        });
    
     // onclick listner for SAVE button
            saveButton.setOnClickListener(new OnClickListener() {  
                public void onClick(View v) { 
                    //capture the image  
                    try {                    
                        saveAsJpg(mBitmap);     
                        startActivity(new Intent(ThisAct.this, MainActivity.class));
                        finish();
                    } catch (IOException e) {                   
                        e.printStackTrace();
                    } 
                }  
            });     
    } 
    
    }
    

    Thanks guys for helping..

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

Sidebar

Related Questions

I am trying to create a delete button over each image that appears in
I'm trying to create a button with a rectangle since we're gonna have different
I'm trying to create a custom button where the foreColor is always crimson and
i am trying to create a Radio button using Cakephp like the one the
I'm trying to create a post button that inserts the latest posts into a
I'm trying to create a simple button that deletes a row from the database.
I'm trying to create a custom control - a button - which will have
I'm trying to create a perfectly circular button, So I created a template from
I'm trying to create a normal rounded rectangular button in a new iPhone app
I'm trying to create a drop down button and its almost working except one

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.