ParseColorString() публичный статический Метод

public static ParseColorString ( string tint ) : Color?
tint string
Результат Color?
Пример #1
0
        public override bool Execute()
        {
            var splash        = MauiSplashScreen[0];
            var colorMetadata = splash.GetMetadata("Color");
            var color         = Utils.ParseColorString(colorMetadata);

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

            Directory.CreateDirectory(Path.GetDirectoryName(OutputFile));
            using var resourceStream = GetType().Assembly.GetManifestResourceStream("MauiSplash.storyboard");
            using var reader         = new StreamReader(resourceStream);
            using var writer         = File.CreateText(OutputFile);

            string image = Path.GetFileNameWithoutExtension(splash.ItemSpec) + ".png";
            float  r     = color.Value.Red / (float)byte.MaxValue;
            float  g     = color.Value.Green / (float)byte.MaxValue;
            float  b     = color.Value.Blue / (float)byte.MaxValue;
            float  a     = color.Value.Alpha / (float)byte.MaxValue;

            while (!reader.EndOfStream)
            {
                var line = string.Format(CultureInfo.InvariantCulture, reader.ReadLine(), image, r, g, b, a);
                writer.WriteLine(line);
            }

            return(!Log.HasLoggedErrors);
        }
        void WriteColors(ITaskItem splash)
        {
            Directory.CreateDirectory(Path.GetDirectoryName(ColorsFile));

            using var writer = XmlWriter.Create(ColorsFile, Settings);
            writer.WriteComment(Comment);
            writer.WriteStartElement("resources");

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

            if (color != null)
            {
                writer.WriteStartElement("color");
                writer.WriteAttributeString("name", "maui_splash_color");
                writer.WriteString(color.ToString());
                writer.WriteEndElement();
            }
            else if (!string.IsNullOrEmpty(colorMetadata))
            {
                Log.LogWarning($"Unable to parse color value '{colorMetadata}' for '{splash.ItemSpec}'.");
            }

            writer.WriteEndDocument();
        }
Пример #3
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);
        }
Пример #4
0
        public static List <ResizeImageInfo> Parse(IEnumerable <ITaskItem> images)
        {
            var r = new List <ResizeImageInfo>();

            if (images == null)
            {
                return(r);
            }

            foreach (var image in images)
            {
                var info = new ResizeImageInfo();

                var fileInfo = new FileInfo(image.GetMetadata("FullPath"));
                if (!fileInfo.Exists)
                {
                    throw new FileNotFoundException("Unable to find background file: " + fileInfo.FullName, fileInfo.FullName);
                }

                info.Filename = fileInfo.FullName;

                info.Alias = image.GetMetadata("Link");

                info.BaseSize = Utils.ParseSizeString(image.GetMetadata("BaseSize"));

                if (bool.TryParse(image.GetMetadata("Resize"), out var rz))
                {
                    info.Resize = rz;
                }
                else if (info.BaseSize == null && !info.IsVector)
                {
                    // By default do not resize non-vector images
                    info.Resize = false;
                }

                var tintColor = image.GetMetadata("TintColor");
                info.TintColor = Utils.ParseColorString(tintColor);
                if (info.TintColor is null && !string.IsNullOrEmpty(tintColor))
                {
                    throw new InvalidDataException($"Unable to parse color value '{tintColor}' for '{info.Filename}'.");
                }

                var color = image.GetMetadata("Color");
                info.Color = Utils.ParseColorString(color);
                if (info.Color is null && !string.IsNullOrEmpty(color))
                {
                    throw new InvalidDataException($"Unable to parse color value '{color}' for '{info.Filename}'.");
                }

                if (bool.TryParse(image.GetMetadata("IsAppIcon"), out var iai))
                {
                    info.IsAppIcon = iai;
                }

                if (float.TryParse(image.GetMetadata("ForegroundScale"), out var fsc))
                {
                    info.ForegroundScale = fsc;
                }

                var fgFile = image.GetMetadata("ForegroundFile");
                if (!string.IsNullOrEmpty(fgFile))
                {
                    var fgFileInfo = new FileInfo(fgFile);
                    if (!fgFileInfo.Exists)
                    {
                        throw new FileNotFoundException("Unable to find foreground file: " + fgFileInfo.FullName, fgFileInfo.FullName);
                    }

                    info.ForegroundFilename = fgFileInfo.FullName;
                }

                // make sure the image is a foreground if this is an icon
                if (info.IsAppIcon && string.IsNullOrEmpty(info.ForegroundFilename))
                {
                    info.ForegroundFilename = info.Filename;
                    info.Filename           = null;
                }

                // TODO:
                // - Parse out custom DPI's

                r.Add(info);
            }

            return(r);
        }
Пример #5
0
        List <SharedImageInfo> ParseImageTaskItems(ITaskItem[] images)
        {
            var r = new List <SharedImageInfo>();

            if (images == null)
            {
                return(r);
            }

            foreach (var image in images)
            {
                var info = new SharedImageInfo();

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

                info.Filename = fileInfo.FullName;

                info.Alias = image.GetMetadata("Link");

                info.BaseSize = Utils.ParseSizeString(image.GetMetadata("BaseSize"));

                if (bool.TryParse(image.GetMetadata("Resize"), out var rz))
                {
                    info.Resize = rz;
                }

                info.TintColor = Utils.ParseColorString(image.GetMetadata("TintColor"));

                if (bool.TryParse(image.GetMetadata("IsAppIcon"), out var iai))
                {
                    info.IsAppIcon = iai;
                }

                if (float.TryParse(image.GetMetadata("ForegroundScale"), out var fsc))
                {
                    info.ForegroundScale = fsc;
                }

                var fgFile = image.GetMetadata("ForegroundFile");
                if (!string.IsNullOrEmpty(fgFile))
                {
                    var bgFileInfo = new FileInfo(info.Filename);

                    if (!Path.IsPathRooted(fgFile))
                    {
                        fgFile = Path.Combine(bgFileInfo.Directory.FullName, fgFile);
                    }
                    else
                    {
                        fgFile = Path.GetFullPath(fgFile);
                    }

                    Logger.Log($"AppIcon Foreground: " + fgFile);

                    if (File.Exists(fgFile))
                    {
                        info.ForegroundFilename = fgFile;
                    }
                }

                // TODO:
                // - Parse out custom DPI's

                r.Add(info);
            }

            return(r);
        }
Пример #6
0
        List <SharedImageInfo> ParseImageTaskItems(ITaskItem[] images)
        {
            var r = new List <SharedImageInfo>();

            if (images == null)
            {
                return(r);
            }

            foreach (var image in images)
            {
                var info = new SharedImageInfo();

                var fileInfo = new FileInfo(image.GetMetadata("FullPath"));
                if (!fileInfo.Exists)
                {
                    throw new FileNotFoundException("Unable to find background file: " + fileInfo.FullName, fileInfo.FullName);
                }

                info.Filename = fileInfo.FullName;

                info.Alias = image.GetMetadata("Link");

                info.BaseSize = Utils.ParseSizeString(image.GetMetadata("BaseSize"));

                if (bool.TryParse(image.GetMetadata("Resize"), out var rz))
                {
                    info.Resize = rz;
                }

                info.TintColor = Utils.ParseColorString(image.GetMetadata("TintColor"));

                if (bool.TryParse(image.GetMetadata("IsAppIcon"), out var iai))
                {
                    info.IsAppIcon = iai;
                }

                if (float.TryParse(image.GetMetadata("ForegroundScale"), out var fsc))
                {
                    info.ForegroundScale = fsc;
                }

                var fgFile = image.GetMetadata("ForegroundFile");
                if (!string.IsNullOrEmpty(fgFile))
                {
                    var fgFileInfo = new FileInfo(fgFile);
                    if (!fgFileInfo.Exists)
                    {
                        throw new FileNotFoundException("Unable to find foreground file: " + fgFileInfo.FullName, fgFileInfo.FullName);
                    }

                    info.ForegroundFilename = fgFileInfo.FullName;
                }

                // TODO:
                // - Parse out custom DPI's

                r.Add(info);
            }

            return(r);
        }