Package selection guidance compiled from public package information, community data, and project usage.
The image_pixels package enables developers to extend an image's background color or create widgets that rely on image dimensions and pixel colors. It provides tools to analyze and manipulate images at the pixel level, making it ideal for custom visual effects, dynamic backgrounds, and responsive UIs based on image content. The package supports multiple platforms including Android, iOS, Web, macOS, Windows, and Linux, ensuring broad compatibility. With a focus on performance and simplicity, it integrates seamlessly into Flutter projects via pub.dev.
Use cases
Dynamic background color extension
Creating widgets based on image dimensions
Pixel-level image analysis
Responsive UIs with image data
Custom visual effects
Image-based layout adjustments
Key features
Extends background color of images
Analyzes pixel colors
Supports image width/height dependencies
Cross-platform compatibility
Lightweight and efficient
Easy integration with Flutter
Suitable for
Developers building image-driven UIs
Designers needing pixel-perfect layouts
Apps requiring dynamic image backgrounds
Projects with responsive image components
Flutter apps targeting multiple platforms
Considerations
Requires image loading before pixel analysis
Performance impact with large images
Limited to static image processing
Not suitable for real-time video
Best used with preloaded images
May need additional caching for repeated use
Original README
Original README snapshot from the linked source repository. Visit the repository for the latest content.
Sponsor
image_pixels
This package allows you to build a widget that depends on, or uses the values of:
The ImagePixels constructor lets you define an image through an imageProvider, and
then use a builder to build a child widget that depends on the image dimensions and the
color of its pixels.
The default constructor lets you provide the imageProvider, the builder, as well as
a defaultColor to be used when reading pixels outside the image bounds or while the
image is still downloading.
For example, this will display the size of the image as a Text widget:
The builder function gives you access to an img parameter of type ImgDetails, with
the following information:
If the image is already available, img.hasImage is true, and img.width
and img.height indicate the image dimensions.
While the image is not yet available,
img.hasImage is false, and img.width and img.height are null.
The functions img.pixelColorAt() and img.pixelColorAtAlignment()
can be used in the builder body to read the color of the image pixels.
If the coordinates point to outside the image, or if the image is not yet available (is
still being downloaded or failed to download), then these functions will return
the defaultColor provided in the ImagePixels constructor.
The img.uiImage parameter contains the image as a ui.Image type. It will be null
while the image is still downloading.
The img.byteData parameter contains the image as a ByteData type. It will be null
while the image is still downloading.
Other use cases
Getting the tapped pixel color: By wrapping the child of the ImagePixel with
a GestureDetector you can obtain the x/y position where the user tapped the image.
From this information, you can then determine the color of the tapped pixel.
Try running
the
Example.
Modifying the image: The child of the ImagePixel can be a CustomPainter. Then,
you can use a canvas to paint whatever you want on top of the image, or else create
an entirely new image from the pixels of the original image.