画线的时候 不管从哪里开始 他的起始点都在左上角
第一条线的结束会跟第二条线的开始自动画条线
其他手机上就没有这个问题
大佬们帮帮忙
效果图
下面是代码
public class HandWrite extends View {
private Paint paint = null;
private Bitmap originalBitmap = null;
private Bitmap new1Bitmap = null;
private Bitmap new2Bitmap = null;
private float clickX = 0,clickY = 0;
private float startX = 0,startY = 0;
private boolean isMove = true;
private boolean isClear = false;
private int color = Color.BLUE;//getResources().getColor(R.color.blue);
private float strokeWidth = 2.0f;
public HandWrite(Context context, AttributeSet attrs)
{
super(context, attrs);
originalBitmap = BaseApplication.getInstance().getSharephoto();
new1Bitmap = Bitmap.createBitmap(originalBitmap);
}
public void setBitmap(Bitmap bitmap){
originalBitmap = bitmap;
new1Bitmap = Bitmap.createBitmap(originalBitmap);
}
public void clear(){
isClear = true;
new2Bitmap = Bitmap.createBitmap(originalBitmap);
invalidate();
}
public void setstyle(float strokeWidth){
this.strokeWidth = strokeWidth;
}
@Override
protected void onDraw(Canvas canvas)
{
super.onDraw(canvas);
canvas.drawBitmap(HandWriting(new1Bitmap), 0, 0,null);
}
Canvas canvas = null;
public Bitmap HandWriting(Bitmap originalBitmap)
{
if(isClear){
canvas = new Canvas(new2Bitmap);
}
else{
canvas = new Canvas(originalBitmap);
// canvas.drawColor(Color.WHITE);
// canvas.setBitmap(originalBitmap);
}
paint = new Paint();
paint.setStyle(Paint.Style.STROKE);
paint.setAntiAlias(true);
paint.setColor(color);
paint.setStrokeWidth(strokeWidth);
if(isMove){
canvas.drawLine(startX, startY, clickX, clickY, paint);
}
startX = clickX;
startY = clickY;
if(isClear){
return new2Bitmap;
}
BaseApplication.getInstance().setSharephoto(originalBitmap);
return originalBitmap;
}
public Bitmap getBitmap(){
return originalBitmap;
}
@Override
public boolean onTouchEvent(MotionEvent event)
{
clickX = event.getX();
clickY = event.getY();
if(event.getAction() == MotionEvent.ACTION_DOWN){
isMove = false;
invalidate();
return true;
}
else if(event.getAction() == MotionEvent.ACTION_MOVE){
isMove = true;
invalidate();
return true;
}
return super.onTouchEvent(event);
}
}