createAndroidMipmaps static method
Implementation
static Future<void> createAndroidMipmaps(String imagePath, String imageName) async {
final File imageFile = File(imagePath);
if (!imageFile.existsSync()) {
log("Das Icon existiert nicht am angegebenen Pfad.", color: PrintColor.red);
return;
}
// Bild laden
List<int> imageBytes = await imageFile.readAsBytes();
Image image = decodeImage(Uint8List.fromList(imageBytes))!;
// Mipmap Größen (angepasst für Android)
Map<String, int> mipmapSizes = {
'mdpi': 48,
'hdpi': 72,
'xhdpi': 96,
'xxhdpi': 144,
'xxxhdpi': 192,
};
// Android Projektverzeichnis (hier kannst du den Pfad auf dein Projekt anpassen)
String androidResDir = 'android/app/src/main/res';
// Erstelle Mipmap-Ordner und speichere die jeweiligen Bilder
for (String folder in mipmapSizes.keys) {
int size = mipmapSizes[folder]!;
String mipmapPath = path.join(androidResDir, 'mipmap-$folder');
Directory(mipmapPath).createSync(recursive: true); // Ordner erstellen
Directory(mipmapPath).listSync().forEach((FileSystemEntity entity) {
if (entity is File && entity.path.contains('ic_static_shortcut_')) {
entity.deleteSync();
}
});
// Bildgröße anpassen
Image resizedImage = copyResize(image, width: size, height: size);
String formattedImageName = imageName;
String outputPath = path.join(mipmapPath, '$formattedImageName.png');
// Bild speichern
File(outputPath).writeAsBytesSync(encodePng(resizedImage));
}
}