2017-06-14 8 views
0

私はインターネット上でこの質問に答えがありません、私はユーザーが選択できるさまざまな色でペイントしようとしています、問題はこのdrawviewは何も描画していません私はここのCustomViewだかOの広告タッチ消しゴムでのみタッチ点 を消去するかわからない:アンドロイドのタッチで描画する方法と消去する方法

public class DrawView extends android.support.v7.widget.AppCompatImageView { 
     private ArrayList<ColouredPaths> mTouches; 
     // Current used colour 
     private int mCurrColour; 
     private Paint mPaint; 
     private boolean erase=false; 
     ColouredPaths mPath; 
     Canvas mCanvas; 
     public void setErase(boolean isErase){ 
    //set erase true or false 
      erase=isErase; 
     } 
     public void setColor(int colour) { 
      mCurrColour = colour; 
     } 

     public DrawView(Context context) { 
      super(context); 
      init(); 
     } 

     // XML constructor 
     public DrawView(Context context, AttributeSet attrs) { 
      super(context, attrs); 
      init(); } 
     private void init() { 
      mTouches = new ArrayList<>(); 
      mPaint = new Paint(); 
      mPaint.setColor(mCurrColour); 
      mPaint.setAntiAlias(true); 
      mPaint.setStrokeWidth(5); 
      mPaint.setStyle(Paint.Style.FILL); 
      mPaint.setStrokeJoin(Paint.Join.ROUND); 
      mPaint.setStrokeCap(Paint.Cap.ROUND); 
     } 
     private float mX, mY; 
     private static final float TOUCH_TOLERANCE = 4; 

     private void touch_start(float x, float y) { 
      mPath.reset(); 
      mPath.moveTo(x, y); 
      mX = x; 
      mY = y; 
     } 

     private void touch_move(float x, float 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() { 
      mPath.lineTo(mX, mY); 
      mPath.reset(); 
      // commit the path to our offscreen 
      mTouches.add(mPath); 
      // kill this so we don't double draw 
      mPath.reset(); 
     } 

     @Override 
     public boolean onTouchEvent(MotionEvent event) { 
      float x = event.getX(); 
      float y = event.getY(); 
      mPath=new ColouredPaths(mCurrColour); 
      switch (event.getAction()) { 
       case MotionEvent.ACTION_DOWN: 
        touch_start(x, y); 

        break; 
       case MotionEvent.ACTION_MOVE: 
        touch_move(x, y); 

        break; 
       case MotionEvent.ACTION_UP: 
        touch_up(); 

        break; 
      } 
      return super.onTouchEvent(event); 
     } 

     @Override 
     protected void onDraw(Canvas c) { 
      // Let the image be drawn first 
      super.onDraw(c); 
      // Draw your custom points here 
        for (ColouredPaths p : mTouches) { 

       mPaint.setColor(p.colour); 
       c.drawPath(p,mPaint);}} 


     /** 
     * Class to store the coordinate and the colour of the point. 
     */ 
     private class ColouredPaths extends Path{ 

      int colour; 

      public ColouredPaths(int colour) { 

       this.colour = colour; 
      } 
     } 
    } 

誰もが答え を提供することができれば、これは私のログでは理解されるであろう。

06-14 21:26:03.926 907-1410/? E/hwintelligencewifi: updataApInfo cellid =4190217533 
06-14 21:26:03.926 907-1410/? E/hwintelligencewifi: addCurrentApInfo cellid =4190217533 
06-14 21:26:03.928 907-1410/? E/hwintelligencewifi: addCurrentApInfo info is already there 
06-14 21:26:03.932 907-1410/? E/hwintelligencewifi: inlineAddCurrentApInfo mInfos.size()=31 
+1

私が気に入っ似た何かをしたときは、[このファイル](https://github.com/SueSmith/android-drawing-app/blob/master/src/com/ example/drawingfun/DrawingView.java)を[this repo](https://github.com/SueSmith/android-drawing-app)に追加します。それはあなたがしようとしているように描画/消去を持っています。それが役立つなら、それはチュートリアル(READMEのリンク)の一部でもあります。 –

+0

@BrettBeattyこれはビットマップイメージ上のイメージビューで使用したい場合はこれを使用できますか? – rgl

+0

申し訳ありませんが、私はその質問を理解していません。その後、ユーザーが描画を完了したら、ビューからビットマップを取得できます(canvasBitmapプロパティを参照)。 –

答えて

0

実際にはあなたの描画ビューでOnTouchListenerを設定します。

だから、ここに行く:Draw images on evey touch co-ordinats Of Imageview

+0

私が追加しましたタッチでリスナーをタッチして、タッチでもパスを描きたい場合は、 – rgl

+0

イベントにログを追加して、あなたのonTouchEventが実際に呼び出されているかどうかを教えてください。 –

+0

私の質問を編集しました – rgl

関連する問題