Ejemplo n.º 1
0
    public byte[] getTileImageData(int x, int y, int zoom) {
      mStream.reset();

      Matrix matrix = new Matrix(mBaseMatrix);
      float scale = (float) (Math.pow(2, zoom) * mScale);
      matrix.postScale(scale, scale);
      matrix.postTranslate(-x * mDimension, -y * mDimension);

      mBitmap.eraseColor(Color.TRANSPARENT);
      Canvas c = new Canvas(mBitmap);
      c.setMatrix(matrix);

      // NOTE: Picture is not thread-safe.
      synchronized (mSvgPicture) {
        mSvgPicture.draw(c);
      }

      BufferedOutputStream stream = new BufferedOutputStream(mStream);
      mBitmap.compress(Bitmap.CompressFormat.PNG, 0, stream);
      try {
        stream.close();
      } catch (IOException e) {
        Log.e(TAG, "Error while closing tile byte stream.");
        e.printStackTrace();
      }
      return mStream.toByteArray();
    }