addImageWatermark static method
This method adds the image that is indicated as a watermark, the parameters are the following:
await addImageWatermark(
originalImageBytes : //Original Image converted to Uint8List
waterkmarkImageBytes: //Watermark Image converted to Uint8List
dstX: //X coordinates in the image (default 100)
dstY: //Y coordinates in the image (default 100)
imgHeight: //Image height (default 100)
imgWidth: //Image width (default 100)
);
Implementation
static Future<Uint8List> addImageWatermark({
required Uint8List originalImageBytes,
required Uint8List waterkmarkImageBytes,
int imgHeight = 100,
int imgWidth = 100,
int dstX = 100,
int dstY = 100,
}) async {
///Original Image
final original = ui.decodeImage(originalImageBytes)!;
///Watermark Image
final watermark = ui.decodeImage(waterkmarkImageBytes)!;
// add watermark over originalImage
// initialize width and height of watermark image
final image = ui.Image(height: imgHeight, width: imgWidth);
ui.compositeImage(image, watermark);
// ui.drawImage(image, watermark);
// give position to watermark over image
ui.compositeImage(
original,
image,
dstX: dstX,
dstY: dstY,
);
///Encode image to PNG
final wmImage = ui.encodePng(original);
///Get the result
final result = Uint8List.fromList(wmImage);
return result;
}