2016-04-13 15 views
0

Ben bir Goole Map çiziyorum çokgen doldurmak için çalışıyordum ama Doğru alamıyorum. Aşağıdaki kodumda, sadece drawPaint kullandığımda, doğru konumda çizerim ama drawPath kullandığımda, farklı konumlarda bitmap resim yapıyor.Tuval drawPath kapalı

Bitmap fillBMP = PatternGenerator.makePattern(PatternGenerator.PATTERN_STYLE_X, lineColor); 
BitmapShader fillBMPshader = new BitmapShader(fillBMP, BitmapShader.TileMode.REPEAT, BitmapShader.TileMode.REPEAT); 
Paint paintshader = new Paint(); 
paintshader.setAntiAlias(true); 
paintshader.setShader(fillBMPshader); 

android.graphics.Point r1 = projection.toScreenLocation(mLatLngBounds.northeast); 
android.graphics.Point r2 = projection.toScreenLocation(mLatLngBounds.southwest); 

int width = Math.abs(Math.abs(r1.x) - Math.abs(r2.x)); 
int height = Math.abs(Math.abs(r2.y) - Math.abs(r1.y)); //Math.abs(r2.y - r1.y); 


Bitmap bm = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888); 
Canvas canvas = new Canvas(bm); 
Paint p = new Paint(); 
p.setColor(Color.YELLOW); 
//canvas.drawPaint(p);  // This works 
canvas.drawPath(path, paintshader); // This does not work. 


GroundOverlay overlay = map.addGroundOverlay(new GroundOverlayOptions() 
     .anchor(0f, 0f) 
     .image(BitmapDescriptorFactory.fromBitmap(bm)) 
     .transparency(0.3f) 
     .positionFromBounds(mLatLngBounds)); 

Oluşturduğum Yol bir dizi nokta.

-23.725012,137.285156 
-24.527135,145.371094 
-29.382175,145.898438 
-29.993002,138.691406 
-23.725012,137.285156 

int nPoints = mOuter.mCoordinates.size(); 

android.graphics.Point pos0 = projection.toScreenLocation(mOuter.mCoordinates.get(0)); 
path.moveTo(pos0.x, pos0.y); 

for (int i = 1; i < nPoints; i++) 
{ 
    builder.include(mOuter.mCoordinates.get(i)); 

    android.graphics.Point pos = projection.toScreenLocation(mOuter.mCoordinates.get(i)); 
    path.lineTo(pos.x, pos.y); 

} 

path.close(); 

Daha sonra moveTo komutunu kullandım ve yolu kapatın.

Burada eksik olduğum bir şey var mı?

cevap

0

Sorunu, Path nesnesinin sınırlayıcı rektini alarak düzelttim. Ve bitmapin çizmek için RectF koordinatlarını kullanın ve yolun başlangıç ​​konumunu dengelemek için RectF'nin .left ve .topunu kullanın.

// This will get the bounding rect of the path and use 
// the width and height of the rect to create the Bitmap. 
RectF rectF = new RectF(); 
path.computeBounds(rectF, true); 

int width = (int)rectF.width(); 
int height = (int)rectF.height(); 

Bitmap bmPattern = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888); 
Canvas canvas = new Canvas(bmPattern); 

// Need to Offset the origin so that it will drawn properly 
canvas.translate(rectF.left * -1, rectF.top * -1); 
canvas.drawPath(path, paintshader);