2013-11-26 44 views
0

我需要顯示兩個地理點之間的連線,但不僅僅是線我需要從資源(R.drawable.line_image)使用一個圖像。那麼我可以畫線或路徑只是我不知道我如何使用圖像。 (我發現很多的例子,但都使用正常的線,而不是與圖像)兩個地理點之間的drawpath與資源圖像

Sombody有什麼幫助或像這樣的例子嗎? THX

我actualy的DrawLine代碼:

Paint paint; 
    paint = new Paint(); 
    paint.setAntiAlias(true); 
    paint.setStyle(Style.STROKE); 
    paint.setStrokeWidth(7); 
    Point pt1 = new Point(); 
    Point pt2 = new Point(); 
    Projection projection = (Projection) mapView.getProjection(); 

    projection.toPixels(start_, pt1); 
    projection.toPixels(end_, pt2); 
    canvas.drawLine(pt1.x, pt1.y, pt2.x, pt2.y, paint); 

回答

0

最後我找到了解決辦法:

@Override 
public void draw(Canvas canvas, MapView mapView, boolean shadow) { 

    Point pt1 = new Point(); 
    Point pt2 = new Point(); 
    Projection projection = (Projection) mapView.getProjection(); 
    projection.toPixels(start_, pt1); 
    projection.toPixels(end_, pt2); 
    Path mPath = new Path(); 
    mPath.moveTo(pt2.x,pt2.y); 
    mPath.lineTo(pt1.x, pt1.y); 
    drawBitmapAlongPath(mPath, bitmap, canvas); 
} 

void drawBitmapAlongPath(Path p, Bitmap b, Canvas c) { 
    Matrix m = new Matrix(); 
    PathMeasure meas = new PathMeasure(p, false); 
    final float length = meas.getLength(); 
    final float advance = b.getWidth(); 
    float distance = 0; 
    final int flags = PathMeasure.POSITION_MATRIX_FLAG | 
      PathMeasure.TANGENT_MATRIX_FLAG; 

    while (distance < length) { 
     meas.getMatrix(distance, m, flags); 
     c.drawBitmap(b, m, null); 
     distance += advance; 
    } 
}