BitmapCanvas class
A painting canvas that includes standard Canvas vector operations, as well as bitmap operations.
Clients must adhere to the lifecycle contract of this object.
Start a new image: To begin painting a new image, call startRecording(), which prepares a new image for painting.
Paint desired content: Vector commands run on the GPU. Pixel painting commands run on the CPU. As a result, these commands must be issued in phases.
When you want to start painting pixels, call startBitmapTransaction.
When you want to shift from pixel painting to vector commands, call endBitmapTransaction.
Produce the final image: To produce an image that you can access, call finishRecording(). The resulting image is available in publishedImage.
You can display the publishedImage in a widget, save it to a file, or send it over the network.
- Implemented types
Constructors
- BitmapCanvas.new({required Size size})
Properties
- canvas → Canvas
-
Collects traditional Flutter vector operations, which are painted by
Flutter's rendering system.
no setter
- hashCode → int
-
The hash code for this object.
no setterinherited
- isDrawing → bool
-
Whether this canvas is in the process of painting a frame.
no setter
- pixels → ByteData?
-
Pixel buffer that holds all pixel values during a bitmap transaction.
no setter
- publishedImage → Image?
-
The latest image to be produced by this BitmapPaintingContext.
no setter
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- size → Size
-
The size of the painting region.
final
Methods
-
clipPath(
Path path, {bool doAntiAlias = true}) → void -
Reduces the clip region to the intersection of the current clip and the
given Path.
override
-
clipRect(
Rect rect, {ClipOp clipOp = ClipOp.intersect, bool doAntiAlias = true}) → void -
Reduces the clip region to the intersection of the current clip and the
given rectangle.
override
-
clipRRect(
RRect rrect, {bool doAntiAlias = true}) → void -
Reduces the clip region to the intersection of the current clip and the
given rounded rectangle.
override
-
clipRSuperellipse(
RSuperellipse rsuperellipse, {bool doAntiAlias = true}) → void -
Reduces the clip region to the intersection of the current clip and the
given rounded superellipse.
inherited
-
drawArc(
Rect rect, double startAngle, double sweepAngle, bool useCenter, Paint paint) → void -
Draw an arc scaled to fit inside the given rectangle.
override
-
drawAtlas(
Image atlas, List< RSTransform> transforms, List<Rect> rects, List<Color> ? colors, BlendMode? blendMode, Rect? cullRect, Paint paint) → void -
Draws many parts of an image - the
atlas
- onto the canvas.override -
drawCircle(
Offset center, double radius, Paint paint) → void -
Draws a circle centered at the point given by the first argument and
that has the radius given by the second argument, with the Paint given in
the third argument. Whether the circle is filled or stroked (or both) is
controlled by Paint.style.
override
-
drawColor(
Color color, BlendMode blendMode) → void -
Paints the given Color onto the canvas, applying the given
BlendMode, with the given color being the source and the background
being the destination.
override
-
drawDRRect(
RRect outer, RRect inner, Paint paint) → void -
Draws a shape consisting of the difference between two rounded rectangles
with the given Paint. Whether this shape is filled or stroked (or both)
is controlled by Paint.style.
override
-
drawImage(
Image image, Offset offset, Paint paint) → void -
Draws the given Image into the canvas with its top-left corner at the
given Offset. The image is composited into the canvas using the given Paint.
override
-
drawImageNine(
Image image, Rect center, Rect dst, Paint paint) → void -
Draws the given Image into the canvas using the given Paint.
override
-
drawImageRect(
Image image, Rect src, Rect dst, Paint paint) → void -
Draws the subset of the given image described by the
src
argument into the canvas in the axis-aligned rectangle given by thedst
argument.override -
drawLine(
Offset p1, Offset p2, Paint paint) → void -
Draws a line between the given points using the given paint. The line is
stroked, the value of the Paint.style is ignored for this call.
override
-
drawOval(
Rect rect, Paint paint) → void -
Draws an axis-aligned oval that fills the given axis-aligned rectangle
with the given Paint. Whether the oval is filled or stroked (or both) is
controlled by Paint.style.
override
-
drawPaint(
Paint paint) → void -
Fills the canvas with the given Paint.
override
-
drawParagraph(
Paragraph paragraph, Offset offset) → void -
Draws the text in the given Paragraph into this canvas at the given
Offset.
override
-
drawPath(
Path path, Paint paint) → void -
Draws the given Path with the given Paint.
override
-
drawPicture(
Picture picture) → void -
Draw the given picture onto the canvas. To create a picture, see
PictureRecorder.
override
-
drawPoints(
PointMode pointMode, List< Offset> points, Paint paint) → void -
Draws a sequence of points according to the given PointMode.
override
-
drawRawAtlas(
Image atlas, Float32List rstTransforms, Float32List rects, Int32List? colors, BlendMode? blendMode, Rect? cullRect, Paint paint) → void -
Draws many parts of an image - the
atlas
- onto the canvas.override -
drawRawPoints(
PointMode pointMode, Float32List points, Paint paint) → void -
Draws a sequence of points according to the given PointMode.
override
-
drawRect(
Rect rect, Paint paint) → void -
Draws a rectangle with the given Paint. Whether the rectangle is filled
or stroked (or both) is controlled by Paint.style.
override
-
drawRRect(
RRect rrect, Paint paint) → void -
Draws a rounded rectangle with the given Paint. Whether the rectangle is
filled or stroked (or both) is controlled by Paint.style.
override
-
drawRSuperellipse(
RSuperellipse rsuperellipse, Paint paint) → void -
Draws a rounded superellipse with the given Paint. The shape is filled,
and the value of the Paint.style is ignored for this call.
inherited
-
drawShadow(
Path path, Color color, double elevation, bool transparentOccluder) → void -
Draws a shadow for a Path representing the given material elevation.
override
-
drawVertices(
Vertices vertices, BlendMode blendMode, Paint paint) → void -
Draws a set of Vertices onto the canvas as one or more triangles.
override
-
endBitmapTransaction(
) → Future< void> - Paints the latest pixels onto the canvas.
-
finishRecording(
) → Future< void> - Produces a new publishedImage based on all the commands that were run since startRecording.
-
get(
int x, int y) → Future< Color> -
Returns the color of the pixel at the given (
x
,y
). -
getDestinationClipBounds(
) → Rect -
Returns the conservative bounds of the combined result of all clip methods
executed within the current save stack of this Canvas object, as measured
in the destination coordinate space in which the Picture will be rendered.
inherited
-
getLocalClipBounds(
) → Rect -
Returns the conservative bounds of the combined result of all clip methods
executed within the current save stack of this Canvas object, as measured
in the local coordinate space under which rendering operations are currently
performed.
inherited
-
getRegion(
{required int x, required int y, required int width, required int height}) → Future< Image> - Returns the colors of all pixels in the given region, represented as an Image.
-
getSaveCount(
) → int -
Returns the number of items on the save stack, including the
initial state. This means it returns 1 for a clean canvas, and
that each call to save and saveLayer increments it, and that
each matching call to restore decrements it.
override
-
getTransform(
) → Float64List -
Returns the current transform including the combined result of all transform
methods executed since the creation of this Canvas object, and respecting the
save/restore history.
inherited
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
restore(
) → void -
Pops the current save stack, if there is anything to pop.
Otherwise, does nothing.
override
-
restoreToCount(
int count) → void -
Restores the save stack to a previous level as might be obtained from getSaveCount.
If
count
is less than 1, the stack is restored to its initial state. Ifcount
is greater than the current getSaveCount then nothing happens.inherited -
rotate(
double radians) → void -
Add a rotation to the current transform. The argument is in radians clockwise.
override
-
save(
) → void -
Saves a copy of the current transform and clip on the save stack.
override
-
saveLayer(
Rect? bounds, Paint paint) → void -
Saves a copy of the current transform and clip on the save stack, and then
creates a new group which subsequent calls will become a part of. When the
save stack is later popped, the group will be flattened into a layer and
have the given
paint
's Paint.colorFilter and Paint.blendMode applied.override -
scale(
double sx, [double? sy]) → void -
Add an axis-aligned scale to the current transform, scaling by the first
argument in the horizontal direction and the second in the vertical
direction.
override
-
set(
{required int x, required int y, required Color color}) → void -
Sets the pixel at the given (
x
,y
) to the givencolor
. -
setRegion(
{required Image image, int x = 0, int y = 0}) → Future< void> -
Sets all pixels in the given region to the colors specified by the given
image
. -
skew(
double sx, double sy) → void -
Add an axis-aligned skew to the current transform, with the first argument
being the horizontal skew in rise over run units clockwise around the
origin, and the second argument being the vertical skew in rise over run
units clockwise around the origin.
override
-
startBitmapTransaction(
) → Future< void> - Prepares the BitmapCanvas to execute a series of bitmap manipulations.
-
startRecording(
) → void - Starts a new image.
-
toString(
) → String -
A string representation of this object.
inherited
-
transform(
Float64List matrix4) → void -
Multiply the current transform by the specified 4⨉4 transformation matrix
specified as a list of values in column-major order.
override
-
translate(
double dx, double dy) → void -
Add a translation to the current transform, shifting the coordinate space
horizontally by the first argument and vertically by the second argument.
override
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited