Search code examples
blackberryblackberry-maps

adjust Bitmap width and height in MapField in BlackBerry


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?


Solution

  • 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++;
    }