Android about creating graffiti board in the process of small problems

Source: Internet
Author: User
Tags transparent color

I have a period of time in the process of making graffiti board in the processing of the eraser function encountered some small problems, the online part of the resources mentioned by the implementation method and I said the basic method of the eraser to achieve a similar idea, the following is the basic idea:

Eraser is the ability to touch the screen with a brush that matches the color of the canvas to achieve the eraser.

1) Initialize the brush and set the color of the brush to white (this is actually set to the color of the canvas).

2) Set the size of the brush to the appropriate size.

3) Use one variable to remember the color of the eraser and use it to reuse the eraser after other actions.


The above is a simple eraser mainly using the same color as the canvas to cover, but when the background map is a photo (background map) is not feasible, because the color will be clearly displayed on the background map, and it is important to note that even if the brush color into a transparent color is not feasible, We chose to use render mode to handle the eraser.

Here we choose the rendering mode xfermode dis_in, so we will find a black shadow border after processing, the effect is achieved, but the bug is very obvious

After selecting the render mode clear this mode erases all pixels, but finds that it is erased in the form of black lines.

Find both solutions through the stack over flow website:

1. Change the path of the Touch_move method of the method of drawing, the effect is achieved but the undo and redo has a certain effect (and the line is no longer smooth), and finally did not choose

private void Touch_move ( float Span class= "PLN" style= "color: #48484c" > x float y ) { float DX = math abs ( x - MX ); float dy = math abs ( my - y ); if ( dx >= touch_tolerance | | dy >= touch_tolerance ) { // 从x1,y1到x2,y2画一条贝塞尔曲线,更平滑(直接用mPath.lineTo也可以) // mPath.quadTo(mX, mY, (x + mX) / 2, (y + mY) / 2);   mpath . lineto ( mx MY ); mCanvas.drawPath(mPath, mPaint);   //将一条完整的路径保存下来(相当于入栈操作) savePath.add(dp); mPath.reset();   mPath.moveTo(mX, mY);     mX= x; mY= y; } }   privatevoid touch_up(){   mPath=null;// 重新置空 //mPath.reset(); } 2. Finally found only need to set the default type to solve the problem
 setLayerType(LAYER_TYPE_SOFTWARE,null);//设置默认样式,去除dis-in的黑色方框以及clear模式的黑线效果
Eraser Related Code
  if     ( currentstyle  ==    1  )    { //normal brush   mPaint.setStrokeWidth(currentSize); mPaint.setColor(currentColor); } else {//橡皮擦 mPaint.setAlpha(0); mpaint   setxfermode   ( new   porterduffxfermode  Span class= "pun" style= "color: #93a1a1" > ( porterduff   mode    dst_in    mpaint   setcolor   ( Span class= "Typ" style= "Color:teal" >color  .  transparent    mPaint.setStrokeWidth(50); }


Android about creating graffiti board in the process of small problems

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.