本文整理汇总了Java中org.mapsforge.core.graphics.Canvas.drawBitmap方法的典型用法代码示例。如果您正苦于以下问题:Java Canvas.drawBitmap方法的具体用法?Java Canvas.drawBitmap怎么用?Java Canvas.drawBitmap使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.mapsforge.core.graphics.Canvas
的用法示例。
在下文中一共展示了Canvas.drawBitmap方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: draw
import org.mapsforge.core.graphics.Canvas; //导入方法依赖的package包/类
@Override
public synchronized void draw(BoundingBox boundingBox, byte zoomLevel, Canvas canvas, Point topLeftPoint) {
if (getLatLong() == null || getBitmap() == null) {
return;
}
long mapSize = MercatorProjection.getMapSize(zoomLevel, displayModel.getTileSize());
double pixelX = MercatorProjection.longitudeToPixelX(getLatLong().longitude, mapSize);
double pixelY = MercatorProjection.latitudeToPixelY(getLatLong().latitude, mapSize);
int halfBitmapWidth = getBitmap().getWidth() / 2;
int halfBitmapHeight = getBitmap().getHeight() / 2;
int left = (int) (pixelX - topLeftPoint.x - halfBitmapWidth + getHorizontalOffset());
int top = (int) (pixelY - topLeftPoint.y - halfBitmapHeight + getVerticalOffset());
int right = left + getBitmap().getWidth();
int bottom = top + getBitmap().getHeight();
Rectangle bitmapRectangle = new Rectangle(left, top, right, bottom);
Rectangle canvasRectangle = new Rectangle(0, 0, canvas.getWidth(), canvas.getHeight());
if (!canvasRectangle.intersects(bitmapRectangle)) {
return;
}
android.graphics.Canvas androidCanvas = AndroidGraphicFactory.getCanvas(canvas);
androidCanvas.save();
androidCanvas.rotate(degree, (float) (pixelX - topLeftPoint.x), (float) (pixelY - topLeftPoint.y));
canvas.drawBitmap(getBitmap(), left, top);
androidCanvas.restore();
}
示例2: draw
import org.mapsforge.core.graphics.Canvas; //导入方法依赖的package包/类
@Override public synchronized void draw(BoundingBox boundingBox, byte zoomLevel, Canvas canvas, Point topLeftPoint) {
if (getLatLong() == null || getBitmap() == null) {
return;
}
long mapSize = MercatorProjection.getMapSize(zoomLevel, displayModel.getTileSize());
double pixelX = MercatorProjection.longitudeToPixelX(getLatLong().longitude, mapSize);
double pixelY = MercatorProjection.latitudeToPixelY(getLatLong().latitude, mapSize);
int halfBitmapWidth = getBitmap().getWidth() / 2;
int halfBitmapHeight = getBitmap().getHeight() / 2;
int left = (int) (pixelX - topLeftPoint.x - halfBitmapWidth + getHorizontalOffset());
int top = (int) (pixelY - topLeftPoint.y - halfBitmapHeight + getVerticalOffset());
int right = left + getBitmap().getWidth();
int bottom = top + getBitmap().getHeight();
Rectangle bitmapRectangle = new Rectangle(left, top, right, bottom);
Rectangle canvasRectangle = new Rectangle(0, 0, canvas.getWidth(), canvas.getHeight());
if (!canvasRectangle.intersects(bitmapRectangle)) {
return;
}
android.graphics.Canvas androidCanvas = AndroidGraphicFactory.getCanvas(canvas);
androidCanvas.save();
androidCanvas.rotate(degree, (float) (pixelX - topLeftPoint.x), (float) (pixelY - topLeftPoint.y));
canvas.drawBitmap(getBitmap(), left, top);
androidCanvas.restore();
}
示例3: 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);
}
}
示例4: call
import org.mapsforge.core.graphics.Canvas; //导入方法依赖的package包/类
@Override
public BufferedImage call() {
// get mapsforge zoom from jxmapviewer2 zoom (they use different conventions)
byte mapsforgeZoom = zoomLevelConverter.getMapsforge(tile.getZoom());
// load the render them
RenderThemeFuture rtf = new RenderThemeFuture(AwtGraphicFactory.INSTANCE, renderTheme, model);
rtf.run();
// render the mapsforge tile
org.mapsforge.core.model.Tile mtile = new org.mapsforge.core.model.Tile(tile.getX(), tile.getY(), mapsforgeZoom, TILE_SIZE);
RendererJob job = new RendererJob(mtile, mapDatabase, rtf, model, TEXT_SCALE, true, false);
TileBitmap bitmap = databaseRenderer.executeJob(job);
// copy it over onto an image (CompressedImage needs TYPE_INT_ARGB and anyway we can't access the buffered image internal to the tile)
BufferedImage image = new BufferedImage(TILE_SIZE, TILE_SIZE, BufferedImage.TYPE_INT_ARGB);
Graphics2D g = (Graphics2D)image.getGraphics();
g.setClip(0, 0, TILE_SIZE, TILE_SIZE);
g.setColor(Color.WHITE);
g.fillRect(0, 0, TILE_SIZE, TILE_SIZE);
Canvas canvas = (Canvas) AwtGraphicFactory.createGraphicContext(g);
canvas.drawBitmap(bitmap, 0, 0);
if(fadeColour!=null){
BackgroundMapUtils.renderFade(g,fadeColour.getColour());
}
g.dispose();
if(fadeColour!=null){
image = BackgroundMapUtils.greyscale(image, fadeColour.getGreyscale());
}
// TEST save to file
// ImageUtils.toPNGFile(image, new File("C:\\temp\\MapsforgeOutput\\" + System.currentTimeMillis() + ".png"));
// add to cache
CompressedImage compressed = new CompressedImage(image, CompressedType.LZ4);
cacheImage(tile.getX(), tile.getY(), tile.getZoom(), compressed);
// remove from pending after adding from cache (so can't be added twice)
removeTile(tile);
return image;
}