org.mapsforge.core.graphics.Bitmap.getWidth()方法的使用及代码示例

x33g5p2x  于2022-01-17 转载在 其他  
字(13.5k)|赞(0)|评价(0)|浏览(112)

本文整理了Java中org.mapsforge.core.graphics.Bitmap.getWidth()方法的一些代码示例,展示了Bitmap.getWidth()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Bitmap.getWidth()方法的具体详情如下:
包路径:org.mapsforge.core.graphics.Bitmap
类名称:Bitmap
方法名:getWidth

Bitmap.getWidth介绍

暂无

代码示例

代码示例来源: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 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

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

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

private static void verifyEquals(Bitmap bitmap1, Bitmap bitmap2) {
  Assert.assertEquals(bitmap1.getWidth(), bitmap2.getWidth());
  Assert.assertEquals(bitmap1.getHeight(), bitmap2.getHeight());
}

代码示例来源: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

/**
 * 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

/**
 * Called from {@link MapView}
 *
 * @param graphicContext The graphicContext to use to draw the MapScaleBar
 */
public void draw(GraphicContext graphicContext) {
  if (!this.visible) {
    return;
  }
  if (this.mapViewDimension.getDimension() == null) {
    return;
  }
  if (this.isRedrawNecessary()) {
    redraw(this.mapScaleCanvas);
    this.redrawNeeded = false;
  }
  int positionLeft = calculatePositionLeft(0, this.mapViewDimension.getDimension().width, this.mapScaleBitmap.getWidth());
  int positionTop = calculatePositionTop(0, this.mapViewDimension.getDimension().height, this.mapScaleBitmap.getHeight());
  graphicContext.drawBitmap(this.mapScaleBitmap, positionLeft, positionTop);
}

代码示例来源:origin: org.mapsforge/mapsforge-map

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

/**
 * Set group marker parameter. To know index and calculate position on spiral.
 *
 * @param index            the index of this child marker.
 * @param bitmap           the bitmap of the group marker.
 * @param horizontalOffset the horizontal offset of the group marker.
 * @param verticalOffset   the vertical offset of the group marker.
 */
public void init(int index, Bitmap bitmap, int horizontalOffset, int verticalOffset) {
  this.index = index;
  this.groupBitmapHalfHeight = bitmap.getHeight() / 2;
  this.groupBitmapHalfWidth = bitmap.getWidth() / 2;
  this.groupHOffset = horizontalOffset;
  this.groupVOffset = verticalOffset;
}

代码示例来源:origin: org.mapsforge/mapsforge-map-awt

@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

@SuppressWarnings("unused")
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
@Override
public void setBitmapShader(org.mapsforge.core.graphics.Bitmap bitmap) {
  if (bitmap == null) {
    return;
  }
  android.graphics.Bitmap androidBitmap = AndroidGraphicFactory.getBitmap(bitmap);
  if (androidBitmap == null) {
    return;
  }
  this.shaderWidth = bitmap.getWidth();
  this.shaderHeight = bitmap.getHeight();
  if (!AndroidGraphicFactory.KEEP_RESOURCE_BITMAPS && Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
    // there is an problem when bitmaps are recycled too early on honeycomb and up,
    // where shaders are corrupted. This problem does of course not arise if
    // the bitmaps are cached for future use.
    // incrementing the refcount stops the recycling, but leaks the bitmap.
    bitmap.incrementRefCount();
  }
  this.paint.setColor(AndroidGraphicFactory.getColor(Color.WHITE));
  this.paint.setShader(new BitmapShader(androidBitmap, TileMode.REPEAT, TileMode.REPEAT));
}

代码示例来源:origin: org.mapsforge/mapsforge-map

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: 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: mapsforge/mapsforge

@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
  setMeasuredDimension(mapScaleBar.getMapScaleBitmap().getWidth(), mapScaleBar.getMapScaleBitmap().getHeight());
}

代码示例来源:origin: mapsforge/mapsforge

private Rectangle getBitmapRectangle(Point center) {
  Boolean isSelected = isSelected();
  return new Rectangle(
      center.x
          - (float) cluster.getClusterManager().markerIconBmps.get(markerType)
          .getBitmap(isSelected).getWidth()
          + cluster.getClusterManager().markerIconBmps.get(markerType).getIconOffset().x,
      center.y
          - (float) cluster.getClusterManager().markerIconBmps.get(markerType)
          .getBitmap(isSelected).getHeight()
          + cluster.getClusterManager().markerIconBmps.get(markerType).getIconOffset().y,
      center.x
          + (float) cluster.getClusterManager().markerIconBmps.get(markerType)
          .getBitmap(isSelected).getWidth()
          + cluster.getClusterManager().markerIconBmps.get(markerType).getIconOffset().x,
      center.y
          + (float) cluster.getClusterManager().markerIconBmps.get(markerType)
          .getBitmap(isSelected).getHeight()
          + cluster.getClusterManager().markerIconBmps.get(markerType).getIconOffset().y);
}

代码示例来源: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: org.mapsforge/mapsforge-map

/**
 * 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: org.mapsforge/mapsforge-map

/**
 * Called from {@link MapView}
 *
 * @param graphicContext The graphicContext to use to draw the MapScaleBar
 */
public void draw(GraphicContext graphicContext) {
  if (!this.visible) {
    return;
  }
  if (this.mapViewDimension.getDimension() == null) {
    return;
  }
  if (this.isRedrawNecessary()) {
    redraw(this.mapScaleCanvas);
    this.redrawNeeded = false;
  }
  int positionLeft = calculatePositionLeft(0, this.mapViewDimension.getDimension().width, this.mapScaleBitmap.getWidth());
  int positionTop = calculatePositionTop(0, this.mapViewDimension.getDimension().height, this.mapScaleBitmap.getHeight());
  graphicContext.drawBitmap(this.mapScaleBitmap, positionLeft, positionTop);
}

代码示例来源: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;
  }
  long mapSize = MercatorProjection.getMapSize(zoomLevel, this.displayModel.getTileSize());
  double pixelX = MercatorProjection.longitudeToPixelX(this.getLatLong().longitude, mapSize);
  double pixelY = MercatorProjection.latitudeToPixelY(this.getLatLong().latitude, mapSize);
  int halfBitmapWidth = this.getBitmap().getWidth() / 2;
  int halfBitmapHeight = this.getBitmap().getHeight() / 2;
  int left = (int) (pixelX - topLeftPoint.x - halfBitmapWidth + this.getHorizontalOffset());
  int top = (int) (pixelY - topLeftPoint.y - halfBitmapHeight + this.getVerticalOffset());
  int right = left + this.getBitmap().getWidth();
  int bottom = top + this.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;
  }
  canvas.drawBitmap(this.getBitmap(), left, top);
  if (this.paintText != null) {
    String text = String.valueOf(this.children.size());
    canvas.drawText(text, left + halfBitmapWidth - 5, top + halfBitmapHeight + 5, this.paintText);
  }
}

相关文章