Image class

An Image is a container for ImageData and other various meta-data representing an image in memory.

Inheritance

Constructors

Image({required int width, required int height, Format format = Format.uint8, int numChannels = 3, bool withPalette = false, Format paletteFormat = Format.uint8, Palette? palette, ExifData? exif, IccProfile? iccp, Map<String, String>? textData, int loopCount = 0, FrameType frameType = FrameType.sequence, Color? backgroundColor, int frameDuration = 0, int frameIndex = 0})
Creates an image with the given dimensions and format.
Image.empty()
Creates an empty image.
Image.from(Image other, {bool noAnimation = false, bool noPixels = false})
Creates a copy of the given Image other.
Image.fromBytes({required int width, required int height, required ByteBuffer bytes, int bytesOffset = 0, Format format = Format.uint8, int? numChannels, int? rowStride, bool withPalette = false, Format paletteFormat = Format.uint8, Palette? palette, ExifData? exif, IccProfile? iccp, ChannelOrder? order, Map<String, String>? textData, int loopCount = 0, FrameType frameType = FrameType.sequence, Color? backgroundColor, int frameDuration = 0, int frameIndex = 0})
Create an image from raw data in bytes.
Image.fromResized(Image other, {required int width, required int height, bool noAnimation = false})

Properties

backgroundColor Color?
The suggested background color to clear the canvas with.
getter/setter pair
bitsPerChannel int
The number of bits per color channel.
no setter
buffer ByteBuffer
The ByteBuffer of the image storage data.
no setter
data ImageData?
getter/setter pair
exif ExifData
The exif metadata for the image. If an ExifData hasn't been created for the image yet, one will be added.
getter/setter pair
extraChannels Map<String, ImageData>?
Named non-color channels used by this image.
getter/setter pair
first Pixel
The first element.
no setterinherited
format Format
The format of the image pixels.
no setter
formatType FormatType
The general type of the format, whether it's Uint data, Int data, or Float data (regardless of precision).
no setter
frameDuration 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
frameIndex int
Index of this image in the parent animations frame list.
getter/setter pair
frames List<Image>
The list of sub-frames for the image, if it's an animation. An image is considered animated if it has more than one frame, as the first frame will be the image itself.
getter/setter pair
frameType FrameType
How should the frames be interpreted? If FrameType.animation, the frames are part of an animated sequence. If FrameType.page, the frames are the pages of a document.
getter/setter pair
hasAlpha bool
True if the Image has an alpha channel.
no setter
hasAnimation bool
An image is considered animated if it has more than one frame, as the first image in the frames list is the image itself.
no setter
hasExif bool
no setter
hashCode int
The hash code for this object.
no setterinherited
hasPalette bool
Is true if the image has a palette.
no setter
height int
The height of the image in pixels.
no setter
iccProfile IccProfile?
getter/setter pair
isEmpty bool
Whether this collection has no elements.
no setterinherited
isHdrFormat bool
Is true if the image is a high dynamic range image.
no setter
isLdrFormat bool
Is true if the image format is a low dynamic range (regular) image.
no setter
isNotEmpty bool
Whether this collection has at least one element.
no setterinherited
isValid bool
Is true if the image is valid and has data.
no setter
iterator Iterator<Pixel>
Returns a pixel iterator for iterating over all of the pixels in the image.
no setteroverride
last Pixel
The last element.
no setterinherited
length int
The number of elements in this Iterable.
no setterinherited
lengthInBytes int
The length in bytes of the image data buffer.
no setter
loopCount int
How many times should the animation loop (0 means forever)?
getter/setter pair
maxChannelValue num
The maximum value of a pixel channel, based on the format of the image. If the image has a palette, this will be the maximum value of a palette color channel. Float format images will have a maxChannelValue of 1.0, though they can have values above that.
no setter
maxIndexValue num
The maximum value of a palette index, based on the format of the image. This differs from maxChannelValue in that it will not be affected by the format of the palette.
no setter
numChannels int
The number of color channels for the image.
no setter
numFrames int
The number of frames in this Image. An Image will have at least one frame, itself, so it's considered animated if it has more than one frame.
no setter
palette Palette?
The palette if the image has one, null otherwise.
getter/setter pair
rowStride int
The length in bytes of a row of pixels in the image buffer.
no setter
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
single Pixel
Checks that this iterable has only one element, and returns that element.
no setterinherited
supportsPalette bool
Is true if this image format supports using a palette.
no setter
textData Map<String, String>?
getter/setter pair
width int
The width of the image in pixels.
no setter

Methods

addFrame([Image? image]) Image
Add a frame to the animation of this Image.
addTextData(Map<String, String> data) → void
Add text metadata to the image.
any(bool test(Pixel element)) bool
Checks whether any element of this iterable satisfies test.
inherited
cast<R>() Iterable<R>
A view of this iterable as an iterable of R instances.
inherited
clear([Color? color]) → void
Set all pixels in the image to the given color. If no color is provided the image will be initialized to 0.
clone({bool noAnimation = false, bool noPixels = false}) Image
Create a copy of this image.
contains(Object? element) bool
Whether the collection contains an element equal to element.
inherited
convert({Format? format, int? numChannels, num? alpha, bool withPalette = false, bool noAnimation = false}) Image
Convert this image to a new format or number of channels, numChannels. If the new number of channels is 4 and the current image does not have an alpha channel, then the given alpha value will be used to set the new alpha channel. If alpha is not provided, then the maxChannelValue will be used to set the alpha. If withPalette is true, and to target format and numChannels has fewer than 256 colors, then the new image will be converted to use a palette.
elementAt(int index) Pixel
Returns the indexth element.
inherited
every(bool test(Pixel element)) bool
Checks whether every element of this iterable satisfies test.
inherited
expand<T>(Iterable<T> toElements(Pixel element)) Iterable<T>
Expands each element of this Iterable into zero or more elements.
inherited
firstWhere(bool test(Pixel element), {Pixel orElse()?}) Pixel
The first element that satisfies the given predicate test.
inherited
fold<T>(T initialValue, T combine(T previousValue, Pixel element)) → T
Reduces a collection to a single value by iteratively combining each element of the collection with an existing value
inherited
followedBy(Iterable<Pixel> other) Iterable<Pixel>
Creates the lazy concatenation of this iterable and other.
inherited
forEach(void action(Pixel element)) → void
Invokes action on each element of this iterable in iteration order.
inherited
getBytes({ChannelOrder? order, num? alpha}) Uint8List
Similar to toUint8List, but will convert the channels of the image pixels to the given order. If that happens, the returned bytes will be a copy and not a direct view of the image data. If the number of channels needed by order differs from what the image has, the bytes will come from a converted image. If the converted image needs an alpha channel added, then you can use the alpha argument to specify the value of the added alpha channel.
getColor(num r, num g, num b, [num? a]) Color
Create a Color object with the format and number of channels of the image.
getExtraChannel(String name) ImageData?
getFrame(int index) Image
Get a frame from this image. If the Image is not animated, this Image will be returned; otherwise the particular frame Image will be returned.
getPixel(int x, int y, [Pixel? pixel]) Pixel
Return the Pixel at the given coordinates. If pixel is provided, it will be updated and returned rather than allocating a new Pixel.
getPixelClamped(int x, int y, [Pixel? pixel]) Pixel
Get the pixel from the given x, y coordinate. If the pixel coordinates are out of range of the image, they will be clamped to the resolution.
getPixelCubic(num fx, num fy) Color
Get the pixel using cubic interpolation for non-integer pixel coordinates.
getPixelIndex(int x, int y) int
getPixelInterpolate(num fx, num fy, {Interpolation interpolation = Interpolation.linear}) Color
Get the pixel using the given interpolation type for non-integer pixel coordinates.
getPixelLinear(num fx, num fy) Color
Get the pixel using linear interpolation for non-integer pixel coordinates.
getPixelSafe(int x, int y, [Pixel? pixel]) Pixel
Get the pixel from the given x, y coordinate. If the pixel coordinates are out of bounds, PixelUndefined is returned.
getRange(int x, int y, int width, int height) Iterator<Pixel>
Returns a pixel iterator for iterating over a rectangular range of pixels in the image.
hasExtraChannel(String name) bool
isBoundsSafe(num x, num y) bool
Returns true if the given pixel coordinates is within the dimensions of the image.
join([String separator = ""]) String
Converts each element to a String and concatenates the strings.
inherited
lastWhere(bool test(Pixel element), {Pixel orElse()?}) Pixel
The last element that satisfies the given predicate test.
inherited
map<T>(T toElement(Pixel e)) Iterable<T>
The current elements of this iterable modified by toElement.
inherited
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
reduce(Pixel combine(Pixel value, Pixel element)) Pixel
Reduces a collection to a single value by iteratively combining elements of the collection using the provided function.
inherited
remapChannels(ChannelOrder order) → void
Remap the color channels to the given order. Normally Image color channels are stored in rgba order for 4 channel images, and rgb order for 3 channel images. This method lets you re-arrange the color channels in-place without needing to clone the image for preparing image data for external usage that requires alternative channel ordering.
setExtraChannel(String name, ImageData? data) → void
setPixel(int x, int y, Color c) → void
Set the color of the pixel at the given coordinates to the color of the given Color c.
setPixelIndex(int x, int y, num i) → void
Set the index value for palette images, or the red channel otherwise.
setPixelR(int x, int y, num i) → void
Set the red (or index) color channel of a pixel.
setPixelRgb(int x, int y, num r, num g, num b) → void
Set the color of the Pixel at the given coordinates to the given color values r, g, b.
setPixelRgba(int x, int y, num r, num g, num b, num a) → void
Set the color of the Pixel at the given coordinates to the given color values r, g, b, and a.
singleWhere(bool test(Pixel element), {Pixel orElse()?}) Pixel
The single element that satisfies test.
inherited
skip(int count) Iterable<Pixel>
Creates an Iterable that provides all but the first count elements.
inherited
skipWhile(bool test(Pixel value)) Iterable<Pixel>
Creates an Iterable that skips leading elements while test is satisfied.
inherited
take(int count) Iterable<Pixel>
Creates a lazy iterable of the count first elements of this iterable.
inherited
takeWhile(bool test(Pixel value)) Iterable<Pixel>
Creates a lazy iterable of the leading elements satisfying test.
inherited
toList({bool growable = true}) List<Pixel>
Creates a List containing the elements of this Iterable.
inherited
toSet() Set<Pixel>
Creates a Set containing the same elements as this iterable.
inherited
toString() String
String representation of the image.
override
toUint8List() Uint8List
Get a Uint8List view of the image storage data.
where(bool test(Pixel element)) Iterable<Pixel>
Creates a new lazy Iterable with all elements that satisfy the predicate test.
inherited
whereType<T>() Iterable<T>
Creates a new lazy Iterable with all elements that have type T.
inherited

Operators

operator ==(Object other) bool
The equality operator.
inherited