Code example for Picture

Methods: beginRecording, endRecording

0
                                                                      // +5) * 
                                                                      // 2); 
        final int center = picBorderWidthAndHeight / 2;
 
        // Record Rose 
        Picture mCompassRose = new Picture();
        final Canvas canvas = mCompassRose.beginRecording(picBorderWidthAndHeight, picBorderWidthAndHeight);
//        Log.w(TAG, "Display Density : " + displayDensity); 
        // Blue triangle pointing north 
        final float topY = mCompassRadius;// (mCompassRadius-3)* displayDensity;
                                          // //(mCompassRadius - 3) * 
                                          // displayDensity; 
        final float arrowX = (mCompassRadius * .1f);// * displayDensity;
        final float arrowY = (mCompassRadius * .8f);// * displayDensity;
        final float baseX = (mCompassRadius * .05f); // 4 * displayDensity;
 
        canvas.drawText("X", center + arrowX, center - arrowY, northPaint);
        canvas.drawText("Y", center - arrowX, center - arrowY, northPaint);
 
        final Path pathNorth = new Path();
        pathNorth.moveTo(center, center - topY);
        pathNorth.lineTo(center + arrowX, center - arrowY);
        pathNorth.lineTo(center + baseX, center - arrowY);
        // 
        pathNorth.lineTo(center + baseX, center);
        pathNorth.lineTo(center - baseX, center);
 
        pathNorth.lineTo(center - baseX, center - arrowY);
        pathNorth.lineTo(center - arrowX, center - arrowY);
 
        pathNorth.lineTo(center, center - topY);
        pathNorth.close();
        canvas.drawPath(pathNorth, northPaint);
 
        // Red triangle pointing south 
        final Path pathSouth = new Path();
        pathSouth.moveTo(center + baseX, center + topY);
        pathSouth.lineTo(center + baseX, center);
        pathSouth.lineTo(center - baseX, center);
        pathSouth.lineTo(center - baseX, center + topY);
        pathSouth.lineTo(center + baseX, center + topY);
        pathSouth.close();
        canvas.drawPath(pathSouth, southPaint);
 
        // Draw a little white dot in the middle 
        canvas.drawCircle(center, center, 2, centerPaint);
 
        mCompassRose.endRecording();
        return mCompassRose;
 
    } 
}