本文整理了Java中org.mapsforge.core.graphics.Bitmap
类的一些代码示例,展示了Bitmap
类的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Bitmap
类的具体详情如下:
包路径:org.mapsforge.core.graphics.Bitmap
类名称:Bitmap
暂无
代码示例来源:origin: mapsforge/mapsforge
@Override
public void setBitmapShader(Bitmap bitmap) {
if (bitmap == null) {
return;
}
this.shaderWidth = bitmap.getWidth();
this.shaderHeight = bitmap.getHeight();
Rectangle rectangle = new Rectangle(0, 0, bitmap.getWidth(), bitmap.getHeight());
this.texturePaint = new TexturePaint(AwtGraphicFactory.getBitmap(bitmap), rectangle);
}
代码示例来源:origin: mapsforge/mapsforge
@Override
public synchronized void onDestroy() {
if (this.bitmap != null) {
this.bitmap.decrementRefCount();
}
}
代码示例来源:origin: mapsforge/mapsforge
public SymbolContainer(Point point, Display display, int priority, Bitmap symbol, float theta, boolean alignCenter) {
super(point, display, priority);
this.symbol = symbol;
this.theta = theta;
this.alignCenter = alignCenter;
if (alignCenter) {
double halfWidth = this.symbol.getWidth() / 2d;
double halfHeight = this.symbol.getHeight() / 2d;
this.boundary = new Rectangle(-halfWidth, -halfHeight, halfWidth, halfHeight);
} else {
this.boundary = new Rectangle(0, 0, this.symbol.getWidth(), this.symbol.getHeight());
}
this.symbol.incrementRefCount();
}
代码示例来源:origin: mapsforge/mapsforge
@Override
public synchronized void draw(BoundingBox boundingBox, byte zoomLevel, Canvas canvas, Point topLeftPoint) {
if (this.latLong == null || this.bitmap == null || this.bitmap.isDestroyed()) {
return;
}
long mapSize = MercatorProjection.getMapSize(zoomLevel, this.displayModel.getTileSize());
double pixelX = MercatorProjection.longitudeToPixelX(this.latLong.longitude, mapSize);
double pixelY = MercatorProjection.latitudeToPixelY(this.latLong.latitude, mapSize);
int halfBitmapWidth = this.bitmap.getWidth() / 2;
int halfBitmapHeight = this.bitmap.getHeight() / 2;
int left = (int) (pixelX - topLeftPoint.x - halfBitmapWidth + this.horizontalOffset);
int top = (int) (pixelY - topLeftPoint.y - halfBitmapHeight + this.verticalOffset);
int right = left + this.bitmap.getWidth();
int bottom = top + this.bitmap.getHeight();
Rectangle bitmapRectangle = new Rectangle(left, top, right, bottom);
Rectangle canvasRectangle = new Rectangle(0, 0, canvas.getWidth(), canvas.getHeight());
if (!canvasRectangle.intersects(bitmapRectangle)) {
return;
}
canvas.drawBitmap(this.bitmap, left, top);
}
代码示例来源:origin: mapsforge/mapsforge
@SuppressWarnings("deprecation")
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
static Marker createTappableMarker(final Context c, int resourceIdentifier,
LatLong latLong) {
Drawable drawable = Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP ? c.getDrawable(resourceIdentifier) : c.getResources().getDrawable(resourceIdentifier);
Bitmap bitmap = AndroidGraphicFactory.convertToBitmap(drawable);
bitmap.incrementRefCount();
return new Marker(latLong, bitmap, 0, -bitmap.getHeight() / 2) {
@Override
public boolean onTap(LatLong geoPoint, Point viewPosition,
Point tapPoint) {
if (contains(viewPosition, tapPoint)) {
Toast.makeText(c,
"The Marker was tapped " + geoPoint.toString(),
Toast.LENGTH_SHORT).show();
return true;
}
return false;
}
};
}
代码示例来源:origin: mapsforge/mapsforge
private float computeVerticalOffset(byte zoomLevel) {
float verticalOffset = this.dyScaled.get(zoomLevel);
if (Position.ABOVE == this.position
|| Position.ABOVE_LEFT == this.position
|| Position.ABOVE_RIGHT == this.position) {
verticalOffset -= this.bitmap.getHeight() / 2f + this.gap;
} else if (Position.BELOW == this.position
|| Position.BELOW_LEFT == this.position
|| Position.BELOW_RIGHT == this.position) {
verticalOffset += this.bitmap.getHeight() / 2f + this.gap;
}
return verticalOffset;
}
代码示例来源:origin: mapsforge/mapsforge
private float computeHorizontalOffset() {
// compute only the offset required by the bitmap, not the text size,
// because at this point we do not know the text boxing
if (Position.RIGHT == this.position || Position.LEFT == this.position
|| Position.BELOW_RIGHT == this.position || Position.BELOW_LEFT == this.position
|| Position.ABOVE_RIGHT == this.position || Position.ABOVE_LEFT == this.position) {
float horizontalOffset = this.bitmap.getWidth() / 2f + this.gap;
if (Position.LEFT == this.position
|| Position.BELOW_LEFT == this.position
|| Position.ABOVE_LEFT == this.position) {
horizontalOffset *= -1f;
}
return horizontalOffset;
}
return 0;
}
代码示例来源:origin: mapsforge/mapsforge
@Override
public void onDestroy() {
handler.removeCallbacks(bitmapChanger);
// we need to increment the ref count here as otherwise the bitmap gets
// destroyed, but we might need to reuse it when this is only part of
// a pause/resume cycle.
current.incrementRefCount();
super.onDestroy();
bitmapRed.decrementRefCount();
bitmapGreen.decrementRefCount();
}
}
代码示例来源:origin: mapsforge/mapsforge
@Override
public void run() {
if (current != null) {
// since we want to keep the green bitmap around, we have to increment
// its ref count, otherwise it gets recycled automatically when it is
// replaced with the other colour.
current.incrementRefCount();
}
if (bitmapGreen.equals(current)) {
marker.setBitmap(bitmapRed);
current = bitmapRed;
} else {
marker.setBitmap(bitmapGreen);
current = bitmapGreen;
}
redrawLayers();
handler.postDelayed(this, 2000);
}
}
代码示例来源:origin: mapsforge/mapsforge
Bitmap create() {
if (dimension.width > 0 && dimension.height > 0) {
Bitmap bitmap = factory.createBitmap(dimension.width, dimension.height, isTransparent);
bitmap.setBackgroundColor(color);
return bitmap;
}
return null;
}
}
代码示例来源:origin: org.mapsforge/mapsforge-map
@Override
public synchronized void draw(BoundingBox boundingBox, byte zoomLevel, Canvas canvas, Point topLeftPoint) {
if (this.latLong == null || this.bitmap == null || this.bitmap.isDestroyed()) {
return;
}
long mapSize = MercatorProjection.getMapSize(zoomLevel, this.displayModel.getTileSize());
double pixelX = MercatorProjection.longitudeToPixelX(this.latLong.longitude, mapSize);
double pixelY = MercatorProjection.latitudeToPixelY(this.latLong.latitude, mapSize);
int halfBitmapWidth = this.bitmap.getWidth() / 2;
int halfBitmapHeight = this.bitmap.getHeight() / 2;
int left = (int) (pixelX - topLeftPoint.x - halfBitmapWidth + this.horizontalOffset);
int top = (int) (pixelY - topLeftPoint.y - halfBitmapHeight + this.verticalOffset);
int right = left + this.bitmap.getWidth();
int bottom = top + this.bitmap.getHeight();
Rectangle bitmapRectangle = new Rectangle(left, top, right, bottom);
Rectangle canvasRectangle = new Rectangle(0, 0, canvas.getWidth(), canvas.getHeight());
if (!canvasRectangle.intersects(bitmapRectangle)) {
return;
}
canvas.drawBitmap(this.bitmap, left, top);
}
代码示例来源:origin: mapsforge/mapsforge
@SuppressWarnings("deprecation")
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
@Override
protected void createLayers() {
super.createLayers();
// Bubble overlays
for (DummyContent.DummyItem item : DummyContent.ITEMS) {
TextView bubbleView = new TextView(this);
Utils.setBackground(bubbleView, Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP ? getDrawable(R.drawable.balloon_overlay_unfocused) : getResources().getDrawable(R.drawable.balloon_overlay_unfocused));
bubbleView.setGravity(Gravity.CENTER);
bubbleView.setMaxEms(20);
bubbleView.setTextSize(15);
bubbleView.setTextColor(Color.BLACK);
bubbleView.setText(item.text);
bubble = Utils.viewToBitmap(this, bubbleView);
bubble.incrementRefCount();
this.mapView.getLayerManager().getLayers().add(new Marker(item.location, bubble, 0, -bubble.getHeight() / 2));
}
}
代码示例来源:origin: org.mapsforge/mapsforge-map
private float computeVerticalOffset(byte zoomLevel) {
float verticalOffset = this.dyScaled.get(zoomLevel);
if (Position.ABOVE == this.position
|| Position.ABOVE_LEFT == this.position
|| Position.ABOVE_RIGHT == this.position) {
verticalOffset -= this.bitmap.getHeight() / 2f + this.gap;
} else if (Position.BELOW == this.position
|| Position.BELOW_LEFT == this.position
|| Position.BELOW_RIGHT == this.position) {
verticalOffset += this.bitmap.getHeight() / 2f + this.gap;
}
return verticalOffset;
}
代码示例来源:origin: mapsforge/mapsforge
/**
* Calculates the required length and value of the scalebar
*
* @param unitAdapter the DistanceUnitAdapter to calculate for
* @return a {@link ScaleBarLengthAndValue} object containing the required scaleBarLength and scaleBarValue
*/
protected ScaleBarLengthAndValue calculateScaleBarLengthAndValue(DistanceUnitAdapter unitAdapter) {
this.prevMapPosition = this.mapViewPosition.getMapPosition();
double groundResolution = MercatorProjection.calculateGroundResolution(this.prevMapPosition.latLong.latitude,
MercatorProjection.getMapSize(this.prevMapPosition.zoomLevel, this.displayModel.getTileSize()));
groundResolution = groundResolution / unitAdapter.getMeterRatio();
int[] scaleBarValues = unitAdapter.getScaleBarValues();
int scaleBarLength = 0;
int mapScaleValue = 0;
for (int scaleBarValue : scaleBarValues) {
mapScaleValue = scaleBarValue;
scaleBarLength = (int) (mapScaleValue / groundResolution);
if (scaleBarLength < (this.mapScaleBitmap.getWidth() - 10)) {
break;
}
}
return new ScaleBarLengthAndValue(scaleBarLength, mapScaleValue);
}
代码示例来源:origin: mapsforge/mapsforge
public static Bitmap getBitmapFromTitle(String title, Paint paint) {
if (!captionViews.containsKey(title)) {
TextView bubbleView = new TextView(context);
Utils.setBackground(bubbleView, context.getResources().getDrawable(R.drawable.caption_background));
bubbleView.setGravity(Gravity.CENTER);
bubbleView.setMaxEms(20);
bubbleView.setTextSize(10);
bubbleView.setPadding(5, -2, 5, -2);
bubbleView.setTextColor(android.graphics.Color.BLACK);
bubbleView.setText(title);
//Measure the view at the exact dimensions (otherwise the text won't center correctly)
int widthSpec = View.MeasureSpec.makeMeasureSpec(paint.getTextWidth(title), View.MeasureSpec.EXACTLY);
int heightSpec = View.MeasureSpec.makeMeasureSpec(paint.getTextHeight(title), View.MeasureSpec.EXACTLY);
bubbleView.measure(widthSpec, heightSpec);
//Layout the view at the width and height
bubbleView.layout(0, 0, paint.getTextWidth(title), paint.getTextHeight(title));
captionViews.put(title, Utils.viewToBitmap(context, bubbleView));
captionViews.get(title).incrementRefCount(); // FIXME: is never reduced!
}
return captionViews.get(title);
}
代码示例来源:origin: mapsforge/mapsforge
/**
* @return the bitmap of the second frame to draw on (may be null).
*/
public synchronized Bitmap getDrawingBitmap() {
if (this.lmBitmap != null) {
this.lmBitmap.setBackgroundColor(this.displayModel.getBackgroundColor());
}
return this.lmBitmap;
}
代码示例来源:origin: mapsforge/mapsforge
public synchronized boolean contains(Point center, Point point) {
// Touch min 20x20 px at baseline mdpi (160dpi)
double width = Math.max(20 * this.displayModel.getScaleFactor(), this.bitmap.getWidth());
double height = Math.max(20 * this.displayModel.getScaleFactor(), this.bitmap.getHeight());
Rectangle r = new Rectangle(
center.x - width / 2 + this.horizontalOffset,
center.y - height / 2 + this.verticalOffset,
center.x + width / 2 + this.horizontalOffset,
center.y + height / 2 + this.verticalOffset);
return r.contains(point);
}
代码示例来源:origin: mapsforge/mapsforge
@Override
public void draw(BoundingBox boundingBox, byte zoomLevel, Canvas canvas, Point topLeftPoint) {
if (this.getLatLong() == null || this.getBitmap() == null || this.getBitmap().isDestroyed()) {
return;
double pixelY = MercatorProjection.latitudeToPixelY(this.getLatLong().latitude, mapSize);
int halfBitmapWidth = this.getBitmap().getWidth() / 2;
int halfBitmapHeight = this.getBitmap().getHeight() / 2;
int top = (int) Math.round(radius * Math.sin(theta)) + topGroup + this.getVerticalOffset();
int right = left + this.getBitmap().getWidth();
int bottom = top + this.getBitmap().getHeight();
代码示例来源:origin: org.mapsforge/mapsforge-core
public SymbolContainer(Point point, Display display, int priority, Bitmap symbol, float theta, boolean alignCenter) {
super(point, display, priority);
this.symbol = symbol;
this.theta = theta;
this.alignCenter = alignCenter;
if (alignCenter) {
double halfWidth = this.symbol.getWidth() / 2d;
double halfHeight = this.symbol.getHeight() / 2d;
this.boundary = new Rectangle(-halfWidth, -halfHeight, halfWidth, halfHeight);
} else {
this.boundary = new Rectangle(0, 0, this.symbol.getWidth(), this.symbol.getHeight());
}
this.symbol.incrementRefCount();
}
代码示例来源:origin: sytolk/TaxiAndroidOpen
@UiThread
void showCarPosition(Cars cars) {
if (TaxiApplication.isMapVisible() && cars != null) {
//final List<Layer> overlayItems = carsOverlay.getOverlayItems();
//overlayItems.clear();
TextView bubbleView = new TextView(this);
Utils.setBackground(bubbleView, getResources().getDrawable(R.drawable.balloon_overlay_unfocused));
bubbleView.setGravity(Gravity.CENTER);
bubbleView.setMaxEms(20);
bubbleView.setTextSize(15);
bubbleView.setTextColor(Color.BLACK);
bubbleView.setText(cars.getNumber());
bubble = Utils.viewToBitmap(this, bubbleView);
bubble.incrementRefCount();
if (cars.getCurrPosNorth() != null && cars.getCurrPosEast() != null) {
Marker marker = new Marker(new LatLong(cars.getCurrPosNorth(), cars.getCurrPosEast()), bubble, 0, -bubble.getHeight() / 2);
//marker.setDisplayModel(this.mapViews.get(0).getModel().displayModel);
carsOverlay.add(marker);
mapView.getLayerManager().getLayers().add(marker);
//Log.i(TAG, "Car:" + cars.getNumber());
}
//carsOverlay.requestRedraw();
}
}
内容来源于网络,如有侵权,请联系作者删除!