Methods Summary |
---|
public Canvas | beginRecording(int width, int height)To record a picture, call beginRecording() and then draw into the Canvas
that is returned. Nothing we appear on screen, but all of the draw
commands (e.g. {@link Canvas#drawRect(Rect, Paint)}) will be recorded.
To stop recording, call endRecording(). After endRecording() the Canvas
that was returned must no longer be used, and nothing should be drawn
into it.
long ni = nativeBeginRecording(mNativePicture, width, height);
mRecordingCanvas = new RecordingCanvas(this, ni);
return mRecordingCanvas;
|
public static android.graphics.Picture | createFromStream(java.io.InputStream stream)Create a new picture (already recorded) from the data in the stream. This
data was generated by a previous call to writeToStream(). Pictures that
have been persisted across device restarts are not guaranteed to decode
properly and are highly discouraged.
Note: a picture created from an input stream cannot be
replayed on a hardware accelerated canvas.
return new Picture(nativeCreateFromStream(stream, new byte[WORKING_STREAM_STORAGE]));
|
public void | draw(Canvas canvas)Draw this picture on the canvas.
Prior to {@link android.os.Build.VERSION_CODES#LOLLIPOP}, this call could
have the side effect of changing the matrix and clip of the canvas
if this picture had imbalanced saves/restores.
Note: This forces the picture to internally call
{@link Picture#endRecording()} in order to prepare for playback.
if (canvas.isHardwareAccelerated()) {
throw new IllegalArgumentException(
"Picture playback is only supported on software canvas.");
}
if (mRecordingCanvas != null) {
endRecording();
}
nativeDraw(canvas.getNativeCanvasWrapper(), mNativePicture);
|
public void | endRecording()Call endRecording when the picture is built. After this call, the picture
may be drawn, but the canvas that was returned by beginRecording must not
be used anymore. This is automatically called if {@link Picture#draw}
or {@link Canvas#drawPicture(Picture)} is called.
if (mRecordingCanvas != null) {
mRecordingCanvas = null;
nativeEndRecording(mNativePicture);
}
|
protected void | finalize()
try {
nativeDestructor(mNativePicture);
} finally {
super.finalize();
}
|
public int | getHeight()Get the height of the picture as passed to beginRecording. This
does not reflect (per se) the content of the picture.
return nativeGetHeight(mNativePicture);
|
public int | getWidth()Get the width of the picture as passed to beginRecording. This
does not reflect (per se) the content of the picture.
return nativeGetWidth(mNativePicture);
|
private static native long | nativeBeginRecording(long nativeCanvas, int w, int h)
|
private static native long | nativeConstructor(long nativeSrcOr0)
|
private static native long | nativeCreateFromStream(java.io.InputStream stream, byte[] storage)
|
private static native void | nativeDestructor(long nativePicture)
|
private static native void | nativeDraw(long nativeCanvas, long nativePicture)
|
private static native void | nativeEndRecording(long nativeCanvas)
|
private static native int | nativeGetHeight(long nativePicture)
|
private static native int | nativeGetWidth(long nativePicture)
|
private static native boolean | nativeWriteToStream(long nativePicture, java.io.OutputStream stream, byte[] storage)
|
public void | writeToStream(java.io.OutputStream stream)Write the picture contents to a stream. The data can be used to recreate
the picture in this or another process by calling createFromStream(...)
The resulting stream is NOT to be persisted across device restarts as
there is no guarantee that the Picture can be successfully reconstructed.
Note: a picture created from an input stream cannot be
replayed on a hardware accelerated canvas.
// do explicit check before calling the native method
if (stream == null) {
throw new NullPointerException();
}
if (!nativeWriteToStream(mNativePicture, stream,
new byte[WORKING_STREAM_STORAGE])) {
throw new RuntimeException();
}
|