applyTo method

  1. @override
Bitmap applyTo(
  1. Bitmap bitmap
)
override

Implementation

@override
Bitmap applyTo(Bitmap bitmap) {
  final width = bitmap.width;
  final height = bitmap.height;

  if (resizeWidth == null && resizeHeight == null) {
    throw UnsupportedError(
      "You have to provide either width or height to resize an image",
    );
  }

  // keep aspect ratio
  final toWidth = resizeWidth ?? (resizeHeight! * (width / height)).toInt();
  final toHeight = resizeHeight ?? (resizeWidth! * (height / width)).toInt();

  final int newBitmapBytesExtent =
      (toWidth * toHeight) * RGBA32BitmapHeader.pixelLength;

  final Bitmap resized = Bitmap.fromHeadless(
    toWidth,
    toHeight,
    Uint8List(newBitmapBytesExtent),
  );

  _resizeCore(
    bitmap.content,
    resized.content,
    width,
    height,
    toWidth,
    toHeight,
  );

  return resized;
}