示例#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();
    }
示例#2
0
    @Override
    protected void onDraw(Canvas canvas) {
      canvas.drawColor(Color.WHITE);

      canvas.drawPicture(mPicture);

      canvas.drawPicture(mPicture, new RectF(0, 100, getWidth(), 200));

      mDrawable.setBounds(0, 200, getWidth(), 300);
      mDrawable.draw(canvas);

      ByteArrayOutputStream os = new ByteArrayOutputStream();
      mPicture.writeToStream(os);
      InputStream is = new ByteArrayInputStream(os.toByteArray());
      canvas.translate(0, 300);
      canvas.drawPicture(Picture.createFromStream(is));
    }
示例#3
0
 /** Attempt to free memory and remove references. */
 public void cleanUp() {
   mBitmap.recycle();
   mBitmap = null;
   try {
     mStream.close();
   } catch (IOException e) {
     // ignore
   }
   mStream = null;
 }