Image class

An image buffer where pixels are encoded into 32-bit unsigned ints (Uint32).

Pixels are stored in 32-bit unsigned integers in #AARRGGBB format. This is to be consistent with the Flutter image data. You can use getBytes to access the pixel data at the byte (channel) level, optionally providing the format to get the image data as. You can use the various color functions, such as getRed, getGreen, getBlue, and getAlpha to access the individual channels of a given pixel color.

If this image is a frame of an animation as decoded by the decodeFrame method of Decoder, then the xOffset, yOffset, width and height determine the area of the canvas this image should be drawn into, as some frames of an animation only modify part of the canvas (recording the part of the frame that actually changes). The decodeAnimation method will always return the fully composed animation, so these coordinate properties are not used.

Constructors

Image(int width, int height, {Channels channels = Channels.rgba, ExifData? exif, ICCProfileData? iccp, Map<String, String>? textData})
Create an image with the given dimensions and format.
Image.from(Image other)
Create a copy of the image other.
Image.fromBytes(int width, int height, List<int> bytes, {ExifData? exif, ICCProfileData? iccp, Format format = Format.rgba, Channels channels = Channels.rgba, Map<String, String>? textData})
Create an image from raw data in bytes.
Image.rgb(int width, int height, {ExifData? exif, ICCProfileData? iccp, Map<String, String>? textData})
Create an image with the given dimensions and format.

Properties

blendMethod ↔ BlendMode
Defines the blending method (alpha compositing) to use when drawing this frame in an animation.
getter/setter pair
channels ↔ Channels
The channels used by this image, indicating whether the alpha channel is used or not. All images have an implicit alpha channel due to the image data being stored in a Uint32, but some images, such as those decoded from a Jpeg, don't use the alpha channel. This allows image encoders that support both rgb and rgba formats, to know which one it should use.
getter/setter pair
data Uint32List
Pixels are encoded into 4-byte Uint32 integers in #AABBGGRR channel order.
final
disposeMethod ↔ DisposeMode
Defines what should be done to the canvas when drawing this frame in an animation.
getter/setter pair
duration int
How long this frame should be displayed, in milliseconds. A duration of 0 indicates no delay and the next frame will be drawn as quickly as it can.
getter/setter pair
exif ↔ ExifData
EXIF data decoded from an image file.
getter/setter pair
hashCode int
The hash code for this object.
no setterinherited
height int
Height of the image.
final
iccProfile ↔ ICCProfileData?
ICC color profile read from an image file.
getter/setter pair
length int
The size of the image buffer.
no setter
numberOfChannels int
The number of channels used by this Image. While all images are stored internally with 4 bytes, some images, such as those loaded from a Jpeg, don't use the 4th (alpha) channel.
no setter
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
textData Map<String, String>?
Some formats, like PNG, can encode and decode text data with the image.
getter/setter pair
width int
Width of the image.
final
xOffset int
x position at which to render the frame. This is used for frames in an animation, such as from an animated GIF.
getter/setter pair
yOffset int
y position at which to render the frame. This is used for frames in an animation, such as from an animated GIF.
getter/setter pair

Methods

addTextData(Map<String, String> data) → void
boundsSafe(int x, int y) bool
Is the given x, y pixel coordinates within the resolution of the image.
clone() Image
Clone this image.
fill(int color) Image
Set all of the pixels of the image to the given color.
fillBackground(int color) → void
Set all of the empty pixels (for png's) of the image to the given color.
getBytes({Format format = Format.rgba}) Uint8List
Get the bytes from the image. You can use this to access the color channels directly, or to pass it to something like an Html canvas context.
getPixel(int x, int y) int
Get the pixel from the given x, y coordinate. Color is encoded in a Uint32 as #AABBGGRR. No range checking is done.
getPixelCubic(num fx, num fy) int
Get the pixel using cubic interpolation for non-integer pixel coordinates.
getPixelInterpolate(num fx, num fy, [Interpolation interpolation = Interpolation.linear]) int
Get the pixel using the given interpolation type for non-integer pixel coordinates.
getPixelLinear(num fx, num fy) int
Get the pixel using linear interpolation for non-integer pixel coordinates.
getPixelSafe(int x, int y) int
Get the pixel from the given x, y coordinate. Color is encoded in a Uint32 as #AABBGGRR. If the pixel coordinates are out of bounds, 0 is returned.
getWhiteBalance({bool asDouble = false}) → dynamic
Return the average gray value of the image.
index(int x, int y) int
Get the buffer index for the x, y pixel coordinates. No range checking is done.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
setPixel(int x, int y, int color) → void
Set the pixel at the given x, y coordinate to the color. No range checking is done.
setPixelRgba(int x, int y, int r, int g, int b, [int a = 0xff]) → void
Set the pixel at the given x, y coordinate to the color r, g, b, a.
setPixelSafe(int x, int y, int color) → void
Set the pixel at the given x, y coordinate to the color. If the pixel coordinates are out of bounds, nothing is done.
toString() String
A string representation of this object.
inherited

Operators

operator %(Image other) Image
Modula the colors of other with the pixels of this image.
operator &(Image other) Image
AND the colors of other with the pixels of this image.
operator *(Image other) Image
Multiply the colors of other with the pixels of this image.
operator +(Image other) Image
Add the colors of other to the pixels of this image.
operator -(Image other) Image
Subtract the colors of other from the pixels of this image.
operator ==(Object other) bool
The equality operator.
inherited
operator [](int index) int
Get a pixel from the buffer. No range checking is done.
operator []=(int index, int color) → void
Set a pixel in the buffer. No range checking is done.
operator |(Image other) Image
OR the colors of other to the pixels of this image.