2017-02-14 167 views
0

我畫了4條線,從中心朝向按鈕,正如我在照片中顯示的那樣。我不知道如何繪製圖片中呈紅色的曲線。繪製曲線線android

[enter image description here]

[enter image description here (simpler)]

Bitmap bitmap = Bitmap.createBitmap((int) getWindowManager() 
      .getDefaultDisplay().getWidth(), (int) getWindowManager() 
      .getDefaultDisplay().getHeight(), Bitmap.Config.ARGB_8888); 
    Canvas canvas = new Canvas(bitmap); 
    drawingImageView.setImageBitmap(bitmap); 
    DisplayMetrics metrics = this.getResources().getDisplayMetrics(); 
    int x = metrics.widthPixels; 
    int y = metrics.heightPixels; 
    Paint paint1 = new Paint() ; 
    paint1.setStrokeWidth(10); 
    int margin = 100; 
    int margin1 = 300; 
    int top = 0 + margin; 
    int bottom = canvas.getHeight() - margin; 
    int left = 0 + margin1; 
    int right = canvas.getWidth() - margin1; 
    int centerX = x/2; 
    int centerY = y/2; 

    canvas.drawLine(centerX, top, centerX, bottom,paint1); 
    canvas.drawLine(left, centerY, right, centerY,paint1); 

回答

1

您需要將其在4個不同的部分(曲線)拆分爲更容易拉 這裏是我的草圖(抱歉快速繪圖)

所以你需要得到4分bezieres,應該是這樣的東西 1日舉下手(描繪點)

path.moveTo(x1, y1); 

然後用接下來的抽獎路徑

cubicTo(x2, y2, x3, y3, x4,y4) 

enter image description here

最後

canvas.drawPath(path, paint); 

相同的步驟使休息3象限/部分 希望這可以幫助您歸檔你的目標

+0

我怎麼能有四點的座標? – CamlX

+0

這是更多的數學計算,你有按鈕(1)的位置x,y相同的按鈕(3)和xy的交點,你可以得到你需要的中點很容易(屏幕寬度/ 2和屏幕高度/ 2) –

+0

android對於點x2? – CamlX