在 BlackBerry 的 MapField 中调整位图宽度和高度

发布于 2024-11-27 08:44:15 字数 1249 浏览 1 评论 0原文

我正在 MapField 中的位置点周围绘制圆圈,如下面给出的代码所示:

 public void drawCircleMap(int [] radius)
{
   int i = 0;
    Graphics graphics = null;
    int x2,y2;
    bmparr = new Bitmap[radius.length];
    for(int j=0;j<radius.length;j++)
    {
                XYPoint fieldOut = new XYPoint();
                convertWorldToField(mPoints[1], fieldOut);
                x2 = fieldOut.x;
                y2 = fieldOut.y;
                bmparr[i] = new Bitmap(getWidth(), getHeight());
                bmparr[i].createAlpha(Bitmap.ALPHA_BITDEPTH_8BPP);
                graphics = Graphics.create( bmparr[i]);
                graphics.setColor(Color.BLUE);
                graphics.drawEllipse(x2, y2, x2+radius[j], y2, x2,y2+radius[j], 0, 360);
                graphics.fillEllipse(x2, y2, x2+radius[j], y2, x2,y2+radius[j], 0, 360);
                i++;
    }

}

protected void paint(Graphics graphics) {
    super.paint(graphics);

    for(int i =0 ;i < bmparr.length;i++)
    {
        graphics.setGlobalAlpha(100);
        graphics.drawBitmap(0, 0,  bmparr[i].getWidth(), bmparr[i].getHeight(), bmparr[i], 0, 0);
    }

}

我想绘制 4 个圆圈,现在当我绘制更多数量的圆圈时,地图似乎会淡出,有人可以告诉我如何绘制吗?可以解决这个问题吗?

I am drawing circles around a location point in the MapField like in the code given below:

 public void drawCircleMap(int [] radius)
{
   int i = 0;
    Graphics graphics = null;
    int x2,y2;
    bmparr = new Bitmap[radius.length];
    for(int j=0;j<radius.length;j++)
    {
                XYPoint fieldOut = new XYPoint();
                convertWorldToField(mPoints[1], fieldOut);
                x2 = fieldOut.x;
                y2 = fieldOut.y;
                bmparr[i] = new Bitmap(getWidth(), getHeight());
                bmparr[i].createAlpha(Bitmap.ALPHA_BITDEPTH_8BPP);
                graphics = Graphics.create( bmparr[i]);
                graphics.setColor(Color.BLUE);
                graphics.drawEllipse(x2, y2, x2+radius[j], y2, x2,y2+radius[j], 0, 360);
                graphics.fillEllipse(x2, y2, x2+radius[j], y2, x2,y2+radius[j], 0, 360);
                i++;
    }

}

protected void paint(Graphics graphics) {
    super.paint(graphics);

    for(int i =0 ;i < bmparr.length;i++)
    {
        graphics.setGlobalAlpha(100);
        graphics.drawBitmap(0, 0,  bmparr[i].getWidth(), bmparr[i].getHeight(), bmparr[i], 0, 0);
    }

}

I want to draw 4 circles, now as i draw more number of circles, the map seems to fade out, Can someone please tell me how i could solve this issue?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

等风来 2024-12-04 08:44:15

我通过为每个位图绘制透明背景解决了这个问题:

bmparr = new Bitmap[radius.length];
for(int j=0;j<radius.length;j++)
{
  XYPoint fieldOut = new XYPoint();
  convertWorldToField(mPoints[1], fieldOut);
  x2 = fieldOut.x;
  y2 = fieldOut.y;
  bmparr[i] = new Bitmap(getWidth(), getHeight());
  bmparr[i].createAlpha(Bitmap.ALPHA_BITDEPTH_8BPP);
  int[] argb = new int[getWidth() * getHeight()];
  bmparr[i].getARGB(argb, 0, getWidth(), 0, 0, getWidth(), getHeight());
  for(int k = 0; k < argb.length; k++)
  {
      argb[k] = 0x00000000;
  }
  bmparr[i].setARGB(argb, 0, getWidth(), 0, 0, getWidth(), getHeight());
  graphics = Graphics.create( bmparr[i]);
  graphics.setColor(Color.BLUE);
  graphics.drawEllipse(x2, y2, x2+radius[j], y2, x2,y2+radius[j], 0, 360);
  graphics.fillEllipse(x2, y2, x2+radius[j], y2, x2,y2+radius[j], 0, 360);
  i++;
}

I have solved this problem by drawing a transparent background for every bitmap:

bmparr = new Bitmap[radius.length];
for(int j=0;j<radius.length;j++)
{
  XYPoint fieldOut = new XYPoint();
  convertWorldToField(mPoints[1], fieldOut);
  x2 = fieldOut.x;
  y2 = fieldOut.y;
  bmparr[i] = new Bitmap(getWidth(), getHeight());
  bmparr[i].createAlpha(Bitmap.ALPHA_BITDEPTH_8BPP);
  int[] argb = new int[getWidth() * getHeight()];
  bmparr[i].getARGB(argb, 0, getWidth(), 0, 0, getWidth(), getHeight());
  for(int k = 0; k < argb.length; k++)
  {
      argb[k] = 0x00000000;
  }
  bmparr[i].setARGB(argb, 0, getWidth(), 0, 0, getWidth(), getHeight());
  graphics = Graphics.create( bmparr[i]);
  graphics.setColor(Color.BLUE);
  graphics.drawEllipse(x2, y2, x2+radius[j], y2, x2,y2+radius[j], 0, 360);
  graphics.fillEllipse(x2, y2, x2+radius[j], y2, x2,y2+radius[j], 0, 360);
  i++;
}
梦萦几度 2024-12-04 08:44:15

我相信你的问题是阿尔法混合。您正在绘制每个图像,一个在另一个之上,大约有 50% 的 Alpha。因此,第一个半径“覆盖”现有像素强度的一半。然后下一个半径覆盖剩余强度的一半,或原始强度的 75%。等等……每次你绘制图像时,它都会掩盖越来越多的原始强度。

如果您希望所有圈子都有共同的强度,您将需要重新考虑您的方法。例如,考虑在单个位图中绘制所有圆圈,然后再将其绘制在地图顶部。或者考虑让每个较大的圆圈在较小的圆圈所在的位置留下一个 100% 透明的“洞”。

I believe your problem is with alpha blending. You are drawing each image, one on top of the other, with approximately 50% alpha. So, the first radius "covers" half of the existing pixel intensity. Then the next radius covers half of the remaining intensity, or 75% of the original intensity. And so on... each time you draw an image, it is covering up more and more of the original intensity.

If you want all of your circles to have a common intensity, you will need to re-think your approach. For example, consider drawing all of your circles in a single bitmap before drawing that on top of the map. Or consider having each larger circle leave a 100% transparent "hole" where the smaller circles will be.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文