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})
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})
Create an image from raw data in bytes. [...]
Image.rgb(int width, int height, {ExifData exif, ICCProfileData iccp})

Properties

blendMethod BlendMode
Defines the blending method (alpha compositing) to use when drawing this frame in an animation.
read / write
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.
read / write
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.
read / write
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.
read / write
exif ↔ ExifData
EXIF data decoded from an image file.
read / write
height int
Height of the image.
final
iccProfile ↔ ICCProfileData
ICC color profile read from an image file.
read / write
length int
The size of the image buffer.
read-only
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.
read-only
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.
read / write
yOffset int
y position at which to render the frame. This is used for frames in an animation, such as from an animated GIF.
read / write
hashCode int
The hash code for this object. [...]
read-only, inherited
runtimeType Type
A representation of the runtime type of the object.
read-only, inherited

Methods

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.
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() int
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.
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.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a non-existent method or property is accessed. [...]
inherited
toString() String
Returns 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 [](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.
operator ==(dynamic other) bool
The equality operator. [...]
inherited