当前位置: 首页>>代码示例>>Java>>正文


Java Canvas.drawText方法代码示例

本文整理汇总了Java中org.mapsforge.core.graphics.Canvas.drawText方法的典型用法代码示例。如果您正苦于以下问题:Java Canvas.drawText方法的具体用法?Java Canvas.drawText怎么用?Java Canvas.drawText使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.mapsforge.core.graphics.Canvas的用法示例。


在下文中一共展示了Canvas.drawText方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: draw

import org.mapsforge.core.graphics.Canvas; //导入方法依赖的package包/类
@Override
public synchronized void draw(BoundingBox boundingBox, byte zoomLevel, Canvas canvas, Point topLeftPoint) {
	if (!this.myLocationEnabled) {
		return;
	}

	this.circle.draw(boundingBox, zoomLevel, canvas, topLeftPoint);
	this.marker.draw(boundingBox, zoomLevel, canvas, topLeftPoint);

	if (lastLocation != null) {
		int tileSize = displayModel.getTileSize();
		int pixelX = (int) (MercatorProjection.longitudeToPixelXWithScaleFactor(lastLocation.getLongitude(), zoomLevel, tileSize) - topLeftPoint.x);
		int pixelY = (int) (MercatorProjection.longitudeToPixelXWithScaleFactor(lastLocation.getLatitude(), zoomLevel, tileSize) - topLeftPoint.y);

		Paint paint = GRAPHIC_FACTORY.createPaint();
		paint.setColor(Color.BLACK);
		Resources r = context.getResources();
		float px = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 25, r.getDisplayMetrics());
		paint.setTextSize(px);
		paint.setTextAlign(Align.CENTER);
		paint.setTypeface(FontFamily.DEFAULT, FontStyle.BOLD);
		float pxY = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 45, r.getDisplayMetrics());
		canvas.drawText(userText, pixelX, pixelY - (int) pxY, paint);
	}
}
 
开发者ID:monossido,项目名称:CoopTDMOrienteering,代码行数:26,代码来源:MyLocationOverlay.java

示例2: draw

import org.mapsforge.core.graphics.Canvas; //导入方法依赖的package包/类
@Override
public synchronized void draw(BoundingBox boundingBox, byte zoomLevel, Canvas canvas, Point topLeftPoint) {
    long mapSize = MercatorProjection.getMapSize(zoomLevel, displayModel.getTileSize());
    int tx = (int)(MercatorProjection.longitudeToPixelX(latLong.longitude, mapSize) - topLeftPoint.x);
    int ty = (int)(MercatorProjection.latitudeToPixelY(latLong.latitude, mapSize) - topLeftPoint.y);
    
    Paint paint = gf.createPaint();
    if (selected) {
    	paint.setColor(brightColor);	
    } else {
    	paint.setColor(darkColor);
    }

    Bitmap tempBitmap = gf.createBitmap(PIN_WIDTH, PIN_HEIGHT);
    Canvas tempCanvas = gf.createCanvas();
    tempCanvas.setBitmap(tempBitmap);
    
    // Draw triangle
    Path path = gf.createPath();
    path.moveTo(PIN_WIDTH/2, PIN_HEIGHT-1);
    path.lineTo((int)(PIN_WIDTH*0.2), PIN_WIDTH/2);
    path.lineTo((int)(PIN_WIDTH*0.8), PIN_WIDTH/2);
    path.close();
    tempCanvas.drawPath(path, paint);
    
    // Draw circle
    tempCanvas.drawCircle(PIN_WIDTH/2, PIN_WIDTH/2, PIN_WIDTH/2, paint);
    
    // Draw category
    paint.setColor(0xffffffff);
    paint.setTextSize(PIN_WIDTH * 0.55f);
    paint.setTypeface(FontFamily.SANS_SERIF, FontStyle.BOLD);
    int cx = (PIN_WIDTH - paint.getTextWidth(category))/2;
    int cy = (int)(PIN_WIDTH/2 + paint.getTextHeight(category)*0.35);
    tempCanvas.drawText(category, cx, cy, paint);

    // Paste pin
    Matrix matrix = gf.createMatrix();
    matrix.translate(tx, ty);
    matrix.scale(scale, scale);
    matrix.rotate((float)Math.toRadians(angle));
    matrix.translate(-PIN_WIDTH/2, -PIN_HEIGHT);
    canvas.drawBitmap(tempBitmap, matrix);

    // Draw label
    if (selected) {
        paint.setColor(0xff000000);
        paint.setTextSize(PIN_WIDTH * 0.4f);
        int margin = 10;
        int lw = paint.getTextWidth(label);
        int lh = paint.getTextHeight(label);
        int fw = lw + margin * 2;
        int fh = lh + margin * 2;
        tempBitmap = gf.createBitmap(fw, fh);
        tempCanvas.setBitmap(tempBitmap);
        tempCanvas.fillColor(0xe0ffd070);
        tempCanvas.drawText(label, margin, lh + margin - 3, paint);

        matrix.reset();
        matrix.translate(tx, ty);
        matrix.scale(scale, scale);
        matrix.rotate((float)Math.toRadians(angle));
        matrix.translate(-fw/2, margin);

        canvas.drawBitmap(tempBitmap, matrix);
    }
}
 
开发者ID:OsmHackTW,项目名称:Geomancer,代码行数:68,代码来源:Pin.java


注:本文中的org.mapsforge.core.graphics.Canvas.drawText方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。