Note that there are some explanatory texts on larger screens.

plurals
  1. POdraw on canvas in different device has different smoothness
    primarykey
    data
    text
    <p>In my application i am used canvas to draw a letter. my code is working .</p> <p>But my problem is smoothness in different devices.</p> <p>I am put screen short </p> <p>1)screen short take from samsung tab 2 7 inch <img src="https://i.stack.imgur.com/g6Q5R.png" alt="enter image description here"></p> <p><img src="https://i.stack.imgur.com/aKh3E.png" alt="enter image description here"></p> <p>2) screen short take from google nexus 7 inch.</p> <p>What is the problem in samsung device why smoothness not working .</p> <p>I am also download such type of drawing application but not properly working in samsung device.</p> <p>Please help me . </p> <p>Below code is used for paint </p> <pre><code>class MyTView extends View { private Canvas mCanvas; private Path mPath; private Paint mBitmapPaint; private Matrix matrix = new Matrix(); private float mX, mY; private static final float TOUCH_TOLERANCE = 4; public MyTView(Context c) { super(c); mBitmap = Bitmap.createBitmap(display.getWidth(), display.getHeight(), Bitmap.Config.ARGB_8888); mCanvas = new Canvas(mBitmap); // set canvas background color white Paint paint = new Paint(); // paint.setColor(Color.WHITE); paint.setStyle(Style.FILL); mCanvas.drawPaint(paint); mPath = new Path(); mBitmapPaint = new Paint(Paint.DITHER_FLAG); } public MyTView(Context c, AttributeSet atrs ) { super(c, atrs); mBitmap = Bitmap.createBitmap(display.getWidth(), display.getHeight(), Bitmap.Config.ARGB_8888); // mBitmap = Bitmap.createBitmap(display.getWidth(), display.getHeight(), Bitmap.Config.ARGB_8888); mCanvas = new Canvas(mBitmap); mPath = new Path(); mBitmapPaint = new Paint(Paint.DITHER_FLAG); } public MyTView(Context c,Bitmap bmp ) { super(c); mBitmap = Bitmap.createBitmap(display.getWidth(), display.getHeight(), Bitmap.Config.ARGB_8888); mCanvas = new Canvas(mBitmap); mPath = new Path(); mBitmapPaint = new Paint(Paint.DITHER_FLAG); mCanvas.drawBitmap(bmp, 0, 0,null); } protected void onDraw(Canvas canvas) { //canvas.drawBitmap(mBitmap, 0, 0, mTPaint); // ORIGINAL canvas.drawBitmap(mBitmap, 0, 0, mBitmapPaint); // ORIGINAL canvas.drawPath(mPath, mTPaint); } public void touch_start(float x, float y) { arrXY.clear(); mPath.moveTo(x, y); mX = x; mY = y; arrXY.add(new XYBean(x, y)); } public void touch_move(float x, float y) { arrXY.add(new XYBean(x, y)); float dx = Math.abs(x - mX); float dy = Math.abs(y - mY); if (dx &gt;= TOUCH_TOLERANCE || dy &gt;= TOUCH_TOLERANCE) { mPath.quadTo(mX, mY, (x + mX)/2, (y + mY)/2); mX = x; mY = y; } } private void touch_up() { btn_replay.setBackgroundResource(R.drawable.button_blue); btn_replay.setTextColor(Color.parseColor("#FFFFFF")); System.out.println("--- touch up event ------"); mPath.lineTo(mX, mY); // commit the path to our offscreen mCanvas.drawPath(mPath, mTPaint); mPath.reset(); getScreenCap(drawLayout); } // mCanvas.drawPath(mPath, mPaint); ++count; isSet = false; //arrXY.clear(); System.out.println("After clearing the arrXY: "+arrXY.size()); isStart = true; postInvalidate(); } @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(); mCanvas.drawPath(mPath, mTPaint); // edited by shreyash break; case MotionEvent.ACTION_MOVE: touch_move(x, y); invalidate(); mCanvas.drawPath(mPath, mTPaint); // edited by shreyash break; case MotionEvent.ACTION_UP: touch_up(); invalidate(); // arrXY.clear(); break; } return true; } } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload