在我的应用程序中,我使用画布绘制字母。我的代码正在运行。
但我的问题是不同设备的平滑度。
我把屏幕放短了
1) 三星 Tab 2 7 英寸屏幕短片
2) 谷歌 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;
}
}