在我的应用程序中,我使用canvas绘制一个字母。 我的代码正在运作。
但我的问题是不同设备的平滑性。
我屏幕不亮
1)屏幕短片取自三星标签2 7英寸
2)从google nexus 7英寸屏幕短片。
三星设备有什么问题,为什么平滑性不起作用。
我也下载了这种类型的绘图应用程序,但没有在三星设备中正常工作。
请帮帮我。
下面的代码用于绘画
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 >= TOUCH_TOLERANCE || dy >= 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;
}
}