Picture
- class Picture
Picturerecords drawing commands made toCanvas.The command stream may be played in whole or in part at a later time.
Pictureis an abstract class.Picturemay be generated byPictureRecorderorDrawable, or fromPicturepreviously saved toDataorStream.Picturemay contain anyCanvasdrawing command, as well as one or moreCanvasmatrix orCanvasclip.Picturehas a cullRect, which is used as a bounding box hint. To limitPicturebounds, useCanvasclip when recording or drawingPicture.Example:
recorder = skia.PictureRecorder() canvas = recorder.beginRecording(skia.Rect(100, 100)) canvas.clear(0xFFFFFFFF) canvas.drawLine(0, 0, 100, 100, skia.Paint()) picture = recorder.finishRecordingAsPicture()
Methods
MakeFromData(data: skia.Data) -> skia.Picture
MakeFromStream(stream: skia.Stream) -> skia.Picture
MakePlaceholder(cull: skia.Rect) -> skia.Picture
__init__(self: skia.Picture, cull: skia.Rect) -> None
approximateBytesUsed(self: skia.Picture) -> int
approximateOpCount(self: skia.Picture, nested: bool = False) -> int
cullRect(self: skia.Picture) -> skia.Rect
makeShader(self: skia.Picture, tmx: skia.TileMode, tmy: skia.TileMode, mode: skia.FilterMode, localMatrix: skia.Matrix = None, tile: skia.Rect = None) -> skia.Shader
playback(self: skia.Picture, canvas: SkCanvas) -> None
ref(self: skia.RefCntBase) -> None
serialize(self: skia.Picture) -> skia.Data
unique(self: skia.RefCntBase) -> bool
uniqueID(self: skia.Picture) -> int
unref(self: skia.RefCntBase) -> None
Methods
- static Picture.MakeFromData(data: skia.Data) skia.Picture
Recreates
Picturethat was serialized into data.Returns constructed
Pictureif successful. Fails if data does not permit constructing validPicture.
- static Picture.MakeFromStream(stream: skia.Stream) skia.Picture
Recreates
Picturethat was serialized into a stream.Returns constructed
Pictureif successful; otherwise, returns nullptr. Fails if data does not permit constructing validPicture.- Parameters:
stream – container for serial data
- Returns:
Pictureconstructed from stream data
- static Picture.MakePlaceholder(cull: skia.Rect) skia.Picture
Returns a placeholder
Picture.Result does not draw, and contains only cull
Rect, a hint of its bounds. Result is immutable; it cannot be changed later. Result identifier is unique.Returned placeholder can be intercepted during playback to insert other commands into
Canvasdraw stream.- Parameters:
cull (skia.Rect) – placeholder dimensions
- Returns:
placeholder with unique identifier
- Picture.__init__(self: skia.Picture, cull: skia.Rect) None
Returns a placeholder
Picture.Result does not draw, and contains only cull
Rect, a hint of its bounds. Result is immutable; it cannot be changed later. Result identifier is unique.Returned placeholder can be intercepted during playback to insert other commands into
Canvasdraw stream.- Parameters:
cull (skia.Rect) – placeholder dimensions
- Returns:
placeholder with unique identifier
- Picture.approximateBytesUsed(self: skia.Picture) int
Returns the approximate byte size of
Picture.Does not include large objects referenced by
Picture.- Returns:
approximate size
- Picture.approximateOpCount(self: skia.Picture, nested: bool = False) int
Returns the approximate number of operations in
Picture.Returned value may be greater or less than the number of
Canvascalls recorded: some calls may be recorded as more than one operation, other calls may be optimized away.- Returns:
approximate operation count
- Picture.cullRect(self: skia.Picture) skia.Rect
Returns cull
Rectfor this picture, passed in whenPicturewas created.Returned
Rectdoes not specify clippingRectforPicture; cull is hint ofPicturebounds.Pictureis free to discard recorded drawing commands that fall outside cull.- Returns:
bounds passed when
Picturewas created
- Picture.makeShader(self: skia.Picture, tmx: skia.TileMode, tmy: skia.TileMode, mode: skia.FilterMode, localMatrix: skia.Matrix = None, tile: skia.Rect = None) skia.Shader
Return a new shader that will draw with this picture.
- Parameters:
tmx (skia.TileMode) – The tiling mode to use when sampling in the x-direction.
tmy (skia.TileMode) – The tiling mode to use when sampling in the y-direction.
localMatrix (skia.Matrix) – Optional matrix used when sampling
tile (skia.Rect) – The tile rectangle in picture coordinates: this represents the subset (or superset) of the picture used when building a tile. It is not affected by localMatrix and does not imply scaling (only translation and cropping). If null, the tile rect is considered equal to the picture bounds.
- Returns:
Returns a new shader object. Note: this function never returns null.
- Picture.playback(self: skia.Picture, canvas: SkCanvas) None
Replays the drawing commands on the specified canvas.
In the case that the commands are recorded, each command in the
Pictureis sent separately to canvas.To add a single command to draw
Pictureto recording canvas, callCanvas.drawPicture()instead.- Parameters:
canvas (skia.Canvas) – receiver of drawing commands
callback – allows interruption of playback
- Picture.ref(self: skia.RefCntBase) None
Increment the reference count.
Must be balanced by a call to
unref().
- Picture.serialize(self: skia.Picture) skia.Data
Returns storage containing
DatadescribingPicture.- Returns:
storage containing serialized
Picture
- Picture.unique(self: skia.RefCntBase) bool
May return true if the caller is the only owner.
Ensures that all previous owner’s actions are complete.
- Picture.uniqueID(self: skia.Picture) int
Returns a non-zero value unique among
Picturein Skia process.- Returns:
identifier for
Picture
- Picture.unref(self: skia.RefCntBase) None
Decrement the reference count.
If the reference count is 1 before the decrement, then delete the object. Note that if this is the case, then the object needs to have been allocated via new, and not on the stack.