BytesMapBitmap class

Represents a BitmapDescriptor that is created from an array of bytes encoded as PNG in Uint8List.

The byteData represents the image in a PNG format, which will be decoded and rendered by the platform. The optional width, height or imagePixelRatio parameters are used to correctly scale the image for display, taking into account the devices pixel ratio.

bitmapScaling controls the scaling behavior:

  • MapBitmapScaling.auto automatically upscales and downscales the image to match the device's pixel ratio or the specified dimensions, maintaining consistency across devices.
  • MapBitmapScaling.none disables automatic scaling, which is useful when performance is a concern or if the asset is already scaled appropriately.

The imagePixelRatio parameter allows to give correct pixel ratio of the image. If the imagePixelRatio is not provided, value is defaulted to the natural resolution of 1.0. To render the asset as sharp as possible, set the imagePixelRatio to the devices pixel ratio. imagePixelRatio is ignored if width or height is provided.

Optionally, width and height can be specified to control the dimensions of the rendered image:

  • If both width and height are non-null, the image will have the specified dimensions, which might distort the original aspect ratio, similar to BoxFit.fill.
  • If only one of width and height is non-null, then the output image will be scaled to the associated width or height, and the other dimension will take whatever value is needed to maintain the image's original aspect ratio. These cases are similar to BoxFit.fitWidth and BoxFit.fitHeight, respectively.

The following example demonstrates how to create an BytesMapBitmap from a list of bytes in Uint8List format:

Uint8List byteData = imageBuffer.asUint8List()
double imagePixelRatio = 2.0; // Pixel density of the image.
BytesMapBitmap bytesMapBitmap = BytesMapBitmap(
  byteData,
  imagePixelRatio: imagePixelRatio,
);

Optionally, width and height can be specified to control the asset's dimensions:

Uint8List byteData = imageBuffer.asUint8List()
BytesMapBitmap bytesMapBitmap = BytesMapBitmap(
  byteData,
  width: 64, // Desired width in logical pixels.
);

To render the bitmap as sharply as possible, set the imagePixelRatio to the device's pixel ratio. This renders the asset at a pixel-to-pixel ratio on the screen, but may result in different logical marker sizes across devices with varying pixel densities.

Uint8List byteData = imageBuffer.asUint8List()
BytesMapBitmap bytesMapBitmap = BytesMapBitmap(
  byteData,
  imagePixelRatio: MediaQuery.maybeDevicePixelRatioOf(context),
);
Inheritance

Constructors

BytesMapBitmap(Uint8List byteData, {MapBitmapScaling bitmapScaling = MapBitmapScaling.auto, double? width, double? height, double? imagePixelRatio})
Constructs a BytesMapBitmap that is created from an array of bytes that must be encoded as PNG in Uint8List.

Properties

bitmapScaling MapBitmapScaling
The scaling method of the bitmap.
finalinherited
byteData Uint8List
The bytes of the bitmap.
final
hashCode int
The hash code for this object.
no setterinherited
height double?
The target height of the bitmap in logical pixels.
finalinherited
imagePixelRatio double
The pixel ratio of the bitmap.
finalinherited
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
width double?
The target width of the bitmap in logical pixels.
finalinherited

Methods

noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toJson() Object
Convert the object to a Json format.
override
toString() String
A string representation of this object.
inherited

Operators

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

Constants

type → const String
The type of the MapBitmap object, used for the JSON serialization.