Exemplo n.º 1
0
        public override bool Execute()
        {
            var splash = MauiSplashScreen[0];

            var img = ResizeImageInfo.Parse(splash);

            Directory.CreateDirectory(IntermediateOutputPath);

            var appTool = new SkiaSharpAppIconTools(img, this);

            Log.LogMessage(MessageImportance.Low, $"Splash Screen: Intermediate Path " + IntermediateOutputPath);

            foreach (var dpi in DpiPath.Windows.SplashScreen)
            {
                Log.LogMessage(MessageImportance.Low, $"Splash Screen: " + dpi);

                var destination = Resizer.GetFileDestination(img, dpi, IntermediateOutputPath);

                Log.LogMessage(MessageImportance.Low, $"Splash Screen Destination: " + destination);

                appTool.Resize(dpi, Path.ChangeExtension(destination, ".png"));
            }

            return(!Log.HasLoggedErrors);
        }
Exemplo n.º 2
0
        void ProcessAppIcon(SharedImageInfo img, ConcurrentBag <ResizedImageInfo> resizedImages)
        {
            var appIconName = img.OutputName;

            // Generate the actual bitmap app icons themselves
            var appIconDpis = DpiPath.GetAppIconDpis(PlatformType, appIconName);

            Log.LogMessage(MessageImportance.Low, $"App Icon");

            // Apple and Android have special additional files to generate for app icons
            if (PlatformType == "android")
            {
                Log.LogMessage(MessageImportance.Low, $"Android Adaptive Icon Generator");

                appIconName = appIconName.ToLowerInvariant();

                var adaptiveIconGen = new AndroidAdaptiveIconGenerator(img, appIconName, IntermediateOutputPath, this);
                var iconsGenerated  = adaptiveIconGen.Generate();

                foreach (var iconGenerated in iconsGenerated)
                {
                    resizedImages.Add(iconGenerated);
                }
            }
            else if (PlatformType == "ios")
            {
                Log.LogMessage(MessageImportance.Low, $"iOS Icon Assets Generator");

                var appleAssetGen = new AppleIconAssetsGenerator(img, appIconName, IntermediateOutputPath, appIconDpis, this);

                var assetsGenerated = appleAssetGen.Generate();

                foreach (var assetGenerated in assetsGenerated)
                {
                    resizedImages.Add(assetGenerated);
                }
            }

            Log.LogMessage(MessageImportance.Low, $"Generating App Icon Bitmaps for DPIs");

            var appTool = new SkiaSharpAppIconTools(img, this);

            Log.LogMessage(MessageImportance.Low, $"App Icon: Intermediate Path " + IntermediateOutputPath);

            foreach (var dpi in appIconDpis)
            {
                Log.LogMessage(MessageImportance.Low, $"App Icon: " + dpi);

                var destination = Resizer.GetFileDestination(img, dpi, IntermediateOutputPath)
                                  .Replace("{name}", appIconName);

                Log.LogMessage(MessageImportance.Low, $"App Icon Destination: " + destination);

                appTool.Resize(dpi, Path.ChangeExtension(destination, ".png"));
            }
        }
Exemplo n.º 3
0
        public ResizedImageInfo Generate()
        {
            string destinationFolder = IntermediateOutputPath;

            string fileName    = Path.GetFileNameWithoutExtension(Info.OutputName);
            string destination = Path.Combine(destinationFolder, $"{fileName}.ico");

            Directory.CreateDirectory(destinationFolder);

            Logger.Log($"Generating ICO: {destination}");

            var tools = new SkiaSharpAppIconTools(Info, Logger);
            var dpi   = new DpiPath(fileName, 1.0m, size: new SKSize(64, 64));

            MemoryStream memoryStream = new MemoryStream();

            tools.Resize(dpi, destination, () => memoryStream);
            memoryStream.Position = 0;

            int numberOfImages = 1;

            using BinaryWriter writer = new BinaryWriter(File.Create(destination));
            writer.Write((short)0x0);             // Reserved. Must always be 0.
            writer.Write((short)0x1);             // Specifies image type: 1 for icon (.ICO) image
            writer.Write((short)numberOfImages);  // Specifies number of images in the file.

            writer.Write((byte)dpi.Size.Value.Width);
            writer.Write((byte)dpi.Size.Value.Height);
            writer.Write((byte)0x0);                // Specifies number of colors in the color palette
            writer.Write((byte)0x0);                // Reserved. Should be 0
            writer.Write((short)0x1);               // Specifies color planes. Should be 0 or 1
            writer.Write((short)0x8);               // Specifies bits per pixel.
            writer.Write((int)memoryStream.Length); // Specifies the size of the image's data in bytes

            int offset = 6 + (16 * numberOfImages); // + length of previous images

            writer.Write(offset);                   // Specifies the offset of BMP or PNG data from the beginning of the ICO/CUR file

            // write png data for each image
            memoryStream.CopyTo(writer.BaseStream);
            writer.Flush();

            return(new ResizedImageInfo {
                Dpi = dpi, Filename = destination
            });
        }
Exemplo n.º 4
0
        public override bool Execute()
        {
            var splash = MauiSplashScreen[0];

            var colorMetadata = splash.GetMetadata("Color");
            var color         = Utils.ParseColorString(colorMetadata);

            if (color == null && !string.IsNullOrEmpty(colorMetadata))
            {
                Log.LogWarning($"Unable to parse color value '{colorMetadata}' for '{splash.ItemSpec}'.");
            }

            var fileInfo = new FileInfo(splash.GetMetadata("FullPath"));

            if (!fileInfo.Exists)
            {
                throw new FileNotFoundException("Unable to find background file: " + fileInfo.FullName, fileInfo.FullName);
            }

            var img = new ResizeImageInfo
            {
                Filename = fileInfo.FullName,
                Color    = color ?? SKColors.Transparent,
            };

            Directory.CreateDirectory(IntermediateOutputPath);

            var appTool = new SkiaSharpAppIconTools(img, this);

            Log.LogMessage(MessageImportance.Low, $"Splash Screen: Intermediate Path " + IntermediateOutputPath);

            foreach (var dpi in DpiPath.Windows.SplashScreen)
            {
                Log.LogMessage(MessageImportance.Low, $"Splash Screen: " + dpi);

                var destination = Resizer.GetFileDestination(img, dpi, IntermediateOutputPath);

                Log.LogMessage(MessageImportance.Low, $"Splash Screen Destination: " + destination);

                appTool.Resize(dpi, Path.ChangeExtension(destination, ".png"));
            }

            return(!Log.HasLoggedErrors);
        }