2012-03-16 63 views
1

如何繪製路徑上從數據庫中存儲的座標帆布的Android ..如何繪製路徑機器人在畫布上

我曾試圖fingerpaint但是當我從數據庫中獲取的座標 其從不同的位置繪製路徑,如果我已經把一個點把它畫吸引了來自最近的畫圖到這個點線..

下面是代碼從數據庫中讀取的座標....

public Cursor read() { 
    Cursor cur = db.query("path_new", null, null, null, null, null, null); 
    StringBuffer sbx_read, sby_read; 

    cur.moveToFirst(); 
    float x1 = 0, y1 = 0; 
    int pid_read = 1; 
    int cur_pid; 
    float mX1 = 0, mY1 = 0; 
    do { 

     sbx_read = new StringBuffer(); 
     sbx_read.append(cur.getString(0)); 
     sby_read = new StringBuffer(); 
     sby_read.append(cur.getString(1)); 
     cur.moveToNext(); 
     Log.d("X", sbx_read.toString()); 
     Log.d("Y", sby_read.toString()); 
     Path mPath1 = new Path(); 

     String[] sbx_read_array = sbx_read.toString().trim().split(","); 
     String[] sby_read_array = sby_read.toString().trim().split(","); 
     // mPath.moveTo(x1, y1); 
     for (int i = 0; i < sbx_read_array.length; i++) { 

      x1 = Float.parseFloat(sbx_read_array[i].toString()); 
      y1 = Float.parseFloat(sby_read_array[i].toString()); 

      mPath1.moveTo(x1, y1); 
      // mPath.reset(); 

      // mX1 = x1; 
      // mY1 = y1; 

      float dx = Math.abs(x1 - mX1); 
      float dy = Math.abs(y1 - mY1); 
      if (dx >= TOUCH_TOLERANCE || dy >= TOUCH_TOLERANCE) { 
       mPath.reset(); 
       mPath1.quadTo(mX1, mY1, (x1 + mX1)/2, (y1 + mY1)/2); 
       mX1 = x1; 
       mY1 = y1; 
       // Log.d("X1", String.valueOf(x1)); 
       // Log.d("mX1", String.valueOf(mX1)); 
       // Log.d("Y1", String.valueOf(y1)); 
       // Log.d("mY1", String.valueOf(mY1)); 

       mPath1.lineTo(mX1, mY1); 
       mCanvas.drawPath(mPath1, mPaint); 

      } 
     } 
    } while (cur.moveToNext()); 
    cur.close(); 
    return cur; 
} 

這裏我正在尋找路徑從數據庫到StringBuffer的&轉換成字符串數組,以便不同的路徑可以在不同的記錄存儲器..

我的表...

X-cordinatrs TEXT, Y-cordinatrs TEXT, Path_id INTEGER, PAGE_NO INTEGER

+0

我不知道答案,但你檢查api演示中的手指畫? – Farhan 2012-03-16 05:50:38

+0

是的,我已檢查其顯示如何通過手指或筆畫.. 它不顯示如何繪製從數據庫中提取的座標的路徑...... – Wolverine 2012-03-16 05:57:59

回答

1

這裏就是答案..

do { 

     sbx_read = new StringBuffer(); 
     sbx_read.append(cur.getString(0)); 
     sby_read = new StringBuffer(); 
     sby_read.append(cur.getString(1)); 

     String[] sbx_read_array = sbx_read.toString().trim().split(","); 
     String[] sby_read_array = sby_read.toString().trim().split(","); 

     for (int i = 0; i < sbx_read_array.length; i++) { 

      x1 = Float.parseFloat(sbx_read_array[i].toString()); 
      y1 = Float.parseFloat(sby_read_array[i].toString()); 

      if (pid != cur.getInt(2)) { 
       pid = cur.getInt(2); 
       mPath1.reset(); 
       mPath1.moveTo(x1, y1); 
      } 
      mPath1.lineTo(x1, y1); 
      mCanvas.drawPath(mPath1, mPaint); 
     } 
    } while (cur.moveToNext()); 
    cur.close(); 

這是Do..While循環的代碼只是用你的代碼替換它.. 它會工作,因爲你想........

+1

thenx .... @Azharahmed – Wolverine 2012-03-19 12:00:10

1

不知道這是否會幫助,但你可以請把代碼

實例化的路徑做之前

Path mPath1 = new Path(); 
do{ } 

和也

過了一會之外將drawPath方法:

while(); 
mCanvas.drawPath(mPath1, mPaint); 

希望它helps.You可能也想看看這個link

+0

對不起,不工作仍然同樣的問題......! ! – Wolverine 2012-03-16 06:12:01