processImage static method
Image
processImage(
- String iconPath, {
- double scaling = 0.65,
})
Implementation
static img.Image processImage(String iconPath, {double scaling = 0.65}) {
final bytes = File(iconPath).readAsBytesSync();
final original = img.decodeImage(bytes);
if (original == null) {
throw "Could not decode splash image.";
}
// LOGIC: Create a 1152x1152 canvas (Android 12 requirement)
// We scale the logo to the requested percentage (default 65%) of the canvas
// to ensure it's inside the 'Safe Zone' circle.
final canvasSize = 1152;
final targetLogoSize = (canvasSize * scaling).toInt();
final resizedLogo = img.copyResize(
original,
width: targetLogoSize,
height: targetLogoSize,
);
final canvas = img.Image(
width: canvasSize,
height: canvasSize,
numChannels: 4,
);
// Center the logo on the transparent canvas
final offset = (canvasSize - targetLogoSize) ~/ 2;
img.compositeImage(canvas, resizedLogo, dstX: offset, dstY: offset);
return canvas;
}