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

  • Home
  • SEARCH
  • 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 8487617
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T21:17:48+00:00 2026-06-10T21:17:48+00:00

/I got the following code: public class SketchActivity extends Activity implements OnClickListener, OnSeekBarChangeListener {

  • 0

/I got the following code:

public class SketchActivity extends Activity implements OnClickListener, OnSeekBarChangeListener {

private MyView myView;

private Button clearBtn;

private ToggleButton embossBtn, blurBtn, eraseBtn, srcaBtn;

private RelativeLayout layout, layout2;

private TextView penSizeTxt;

SharedPreferences pref;

private Preview preview;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
    setContentView(R.layout.activity_main);

    init();
    preview = new Preview(this);

    layout2 = (RelativeLayout) findViewById(R.id.paint_layout2);
    layout = (RelativeLayout) findViewById(R.id.paint_layout);
    layout.addView(preview);
    new Handler().postDelayed(new Runnable() {

        @Override
        public void run() {
            myView = new MyView(SketchActivity.this, layout.getWidth(), layout.getHeight());

            layout2.addView(myView);
            layout2.bringToFront();

        }
    }, 50);

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

    mEmboss = new EmbossMaskFilter(new float[] { 1, 1, 1 }, 0.4f, 6, 3.5f);
    mBlur = new BlurMaskFilter(8, BlurMaskFilter.Blur.NORMAL);
}

private void init() {

    clearBtn = (Button) findViewById(R.id.clearBtn);

    embossBtn = (ToggleButton) findViewById(R.id.embossBtn);
    blurBtn = (ToggleButton) findViewById(R.id.blurBtn);
    eraseBtn = (ToggleButton) findViewById(R.id.eraseBtn);
    srcaBtn = (ToggleButton) findViewById(R.id.srcatopBtn);

    clearBtn.setOnClickListener(this);
    embossBtn.setOnClickListener(this);
    blurBtn.setOnClickListener(this);
    eraseBtn.setOnClickListener(this);
    srcaBtn.setOnClickListener(this);
}

private static Paint mPaint;

private MaskFilter mEmboss;

private MaskFilter mBlur;

public void colorChanged(int color) {
    mPaint.setColor(color);
}

private void setToggleOf() {
    embossBtn.setChecked(false);
    eraseBtn.setChecked(false);
    blurBtn.setChecked(false);
    srcaBtn.setChecked(false);
}

@Override
public void onClick(View v) {
    if (v.getId() == embossBtn.getId()) {

        if (mPaint.getMaskFilter() != mEmboss) {
            setToggleOf();
            mPaint.setXfermode(null);
            mPaint.setAlpha(0xFF);
            mPaint.setMaskFilter(mEmboss);
            embossBtn.setChecked(true);
        } else {
            mPaint.setMaskFilter(null);
            embossBtn.setChecked(false);
        }
    } else if (v.getId() == blurBtn.getId()) {

        if (mPaint.getMaskFilter() != mBlur) {
            setToggleOf();
            mPaint.setXfermode(null);
            mPaint.setAlpha(0xFF);
            mPaint.setMaskFilter(mBlur);
            blurBtn.setChecked(true);
        } else {
            mPaint.setMaskFilter(null);
            blurBtn.setChecked(false);
        }
    } else if (v.getId() == eraseBtn.getId()) {
        if (eraseBtn.isChecked()) {
            setToggleOf();
            eraseBtn.setChecked(true);
            mPaint.setMaskFilter(null);
            mPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.CLEAR));

        } else {
            mPaint.setMaskFilter(null);
            mPaint.setXfermode(null);
            mPaint.setAlpha(0xFF);

        }
    } else if (v.getId() == srcaBtn.getId()) {
        if (srcaBtn.isChecked()) {
            setToggleOf();
            mPaint.setMaskFilter(null);
            srcaBtn.setChecked(true);
            mPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_ATOP));
            mPaint.setAlpha(0x80);
        } else {
            mPaint.setMaskFilter(null);
            mPaint.setXfermode(null);
            mPaint.setAlpha(0xFF);
        }

    }

    else if (v.getId() == clearBtn.getId()) {
        layout2.removeAllViews();
        myView = new MyView(SketchActivity.this, layout.getWidth(), layout.getHeight());
        layout2.addView(myView);
    }

}

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;

    Bitmap bitmap;

    int x = 0;

    int y = 0;

    int r = 0;

    public MyView(Context c, int width, int height) {
        super(c);

        WindowManager wm = (WindowManager) c.getSystemService(Context.WINDOW_SERVICE);
        Display display = wm.getDefaultDisplay();
        int w = display.getWidth(); // deprecated
        int h = display.getHeight();
        // setFocusable(true);
        // setBackgroundResource(R.drawable.download);

        // setting paint
        mPath = new Path();
        mPaint = new Paint();

        mPaint.setAlpha(0);
        mPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.DST_IN));
        mPaint.setAntiAlias(true);
        mPaint.setMaskFilter(new BlurMaskFilter(10, BlurMaskFilter.Blur.NORMAL));
        mBitmapPaint = new Paint(Paint.DITHER_FLAG);

        this.getContext().getResources();

        Bitmap bm = BitmapFactory.decodeResource(getResources(), R.drawable.smoke);
        Bitmap bm2 = getResizedBitmap(bm, h, w);

        // converting image bitmap into mutable bitmap

        bitmap = bm2.createBitmap(w, h, Config.ARGB_8888);
        mCanvas = new Canvas();
        mCanvas.setBitmap(bitmap); // drawXY will result on that Bitmap
        mCanvas.drawBitmap(bm2, 0, 0, null);

    }

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

    @Override
    protected void onDraw(Canvas canvas) {
        //mCanvas.drawCircle(x, y, r, mPaint);

        // canvas.drawBitmap(bitmap, 0, 0, null);
        canvas.drawBitmap(bitmap, 0, 0, mBitmapPaint);

        canvas.drawPath(mPath, mPaint);

        super.onDraw(canvas);

    }

    private float mX, mY;

    private static final float TOUCH_TOLERANCE = 4;

    private void touch_start(float x, float y) {
        mPath.reset();
        mPath.moveTo(x, y);
        // mPath.lineTo(x, y);
        // mCanvas.drawPoint(x, y, mPaint);
        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;
        }
        // invalidate();
    }

    private void 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) {
        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 Bitmap getImage() {
        return mBitmap;
    }
}

@Override
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
    // TODO Auto-generated method stub
    penSizeTxt.setText(String.valueOf(progress + 2));

}

@Override
public void onStartTrackingTouch(SeekBar seekBar) {
    // TODO Auto-generated method stub

}

@Override
public void onStopTrackingTouch(SeekBar seekBar) {
    // TODO Auto-generated method stub

}

public Bitmap getResizedBitmap(Bitmap bm, int newHeight, int newWidth) {
    int width = bm.getWidth();
    int height = bm.getHeight();
    float scaleWidth = ((float) newWidth) / width;
    float scaleHeight = ((float) newHeight) / height;
    // CREATE A MATRIX FOR THE MANIPULATION
    Matrix matrix = new Matrix();
    // RESIZE THE BIT MAP
    matrix.postScale(scaleWidth, scaleHeight);
    // RECREATE THE NEW BITMAP
    Bitmap resizedBitmap = Bitmap.createBitmap(bm, 0, 0, width, height, matrix, false);
    return resizedBitmap;
}

}

I want it to clear the second layout and show the content of the camera, on touch. So that if i make a curved line with my finger on the screen it would set those pixels to alpha, and see the camera from the back layout. The problem is that if for example, i make a curved line, the app erases the content of that curve too. So that if i would make a circle with my finger it would erase the content of the circle too, not only the margin.

A screenshot with how it looks: https://i.stack.imgur.com/BlYgU.jpg

  • 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-10T21:17:50+00:00Added an answer on June 10, 2026 at 9:17 pm

    onCreate i had:

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

    And then on my View i had:

     mPaint = new Paint();
     mPaint.setAlpha(0);
     mPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.DST_IN));
     mPaint.setAntiAlias(true);
     mPaint.setMaskFilter(new BlurMaskFilter(10, BlurMaskFilter.Blur.NORMAL));
    

    Overriding the mPaint, and that’s what made it not work properly. By deleting the second:

     mPaint = new Paint();
    

    I made it work

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

Sidebar

Related Questions

In the following code: public class ColorTableDialog extends Dialog implements View.OnClickListener { public ColorTableDialog(Context
i have executed the following code public class Activity_Threads_Handler extends Activity { private int
Hi guyzz I have TabActivity as following simple code public class TabhostActivity extends Activity{
I'v got the following code : public class MyModule: IModule { private IRegionManager mRegionManager
Let's assume we've got the following Java code: public class Maintainer { private Map<Enum,
I got the following code : public class PluginShape : INotifyPropertyChanged { private string
I got the following code: import java.security.MessageDigest; import java.security.NoSuchAlgorithmException; public class Sha1{ private static
I've got the following code: Public Delegate Sub SetStatusBarTextDelegate(ByVal StatusText As String) Private Sub
I just got to read the following code somewhere : public class SingletonObjectDemo {
I've got the following code: Simple Classes public class Transport { } public class

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.