Ejemplo n.º 1
0
        System.Threading.Tasks.Task DoExecute()
        {
            Svg.SvgDocument.SkipGdiPlusCapabilityCheck = true;

            var images = ParseImageTaskItems(SharedImages);

            var dpis = DpiPath.GetDpis(PlatformType);

            if (dpis == null || dpis.Length <= 0)
            {
                return(System.Threading.Tasks.Task.CompletedTask);
            }

            var originalScaleDpi = DpiPath.GetOriginal(PlatformType);

            var resizedImages = new ConcurrentBag <ResizedImageInfo>();

            System.Threading.Tasks.Parallel.ForEach(images, img =>
            {
                try
                {
                    var opStopwatch = new Stopwatch();
                    opStopwatch.Start();

                    string op;

                    if (img.IsAppIcon)
                    {
                        // App icons are special
                        ProcessAppIcon(img, resizedImages);

                        op = "App Icon";
                    }
                    else
                    {
                        // By default we resize, but let's make sure
                        if (img.Resize)
                        {
                            ProcessImageResize(img, dpis, resizedImages);

                            op = "Resize";
                        }
                        else
                        {
                            // Otherwise just copy the thing over to the 1.0 scale
                            ProcessImageCopy(img, originalScaleDpi, resizedImages);

                            op = "Copy";
                        }
                    }

                    opStopwatch.Stop();

                    Log.LogMessage(MessageImportance.Low, $"{op} took {opStopwatch.ElapsedMilliseconds}ms");
                }
                catch (Exception ex)
                {
                    Log.LogErrorFromException(ex);

                    throw;
                }
            });

            var copiedResources = new List <TaskItem>();

            foreach (var img in resizedImages)
            {
                var    attr     = new Dictionary <string, string>();
                string itemSpec = Path.GetFullPath(img.Filename);

                // Fix the item spec to be relative for mac
                if (bool.TryParse(IsMacEnabled, out bool isMac) && isMac)
                {
                    itemSpec = img.Filename;
                }

                // Add DPI info to the itemspec so we can use it in the targets
                attr.Add("_ResizetizerDpiPath", img.Dpi.Path);
                attr.Add("_ResizetizerDpiScale", img.Dpi.Scale.ToString());

                copiedResources.Add(new TaskItem(itemSpec, attr));
            }

            CopiedResources = copiedResources.ToArray();

            return(System.Threading.Tasks.Task.CompletedTask);
        }
Ejemplo n.º 2
0
        public override System.Threading.Tasks.Task ExecuteAsync()
        {
            var images = ResizeImageInfo.Parse(Images);

            var dpis = DpiPath.GetDpis(PlatformType);

            if (dpis == null || dpis.Length <= 0)
            {
                return(System.Threading.Tasks.Task.CompletedTask);
            }

            var originalScaleDpi = DpiPath.GetOriginal(PlatformType);

            var resizedImages = new ConcurrentBag <ResizedImageInfo>();

            this.ParallelForEach(images, img =>
            {
                try
                {
                    var opStopwatch = new Stopwatch();
                    opStopwatch.Start();

                    string op;

                    if (img.IsAppIcon)
                    {
                        // App icons are special
                        ProcessAppIcon(img, resizedImages);

                        op = "App Icon";
                    }
                    else
                    {
                        // By default we resize, but let's make sure
                        if (img.Resize)
                        {
                            ProcessImageResize(img, dpis, resizedImages);

                            op = "Resize";
                        }
                        else
                        {
                            // Otherwise just copy the thing over to the 1.0 scale
                            ProcessImageCopy(img, originalScaleDpi, resizedImages);

                            op = "Copy";
                        }
                    }

                    opStopwatch.Stop();

                    LogDebugMessage($"{op} took {opStopwatch.ElapsedMilliseconds}ms");
                }
                catch (Exception ex)
                {
                    LogWarning("MAUI0000", ex.ToString());

                    throw;
                }
            });

            if (PlatformType == "tizen")
            {
                var tizenResourceXmlGenerator = new TizenResourceXmlGenerator(IntermediateOutputPath, Logger);
                tizenResourceXmlGenerator.Generate();
            }

            var copiedResources = new List <TaskItem>();

            foreach (var img in resizedImages)
            {
                var    attr     = new Dictionary <string, string>();
                string itemSpec = Path.GetFullPath(img.Filename);

                // Fix the item spec to be relative for mac
                if (bool.TryParse(IsMacEnabled, out bool isMac) && isMac)
                {
                    itemSpec = img.Filename;
                }

                // Add DPI info to the itemspec so we can use it in the targets
                attr.Add("_ResizetizerDpiPath", img.Dpi.Path);
                attr.Add("_ResizetizerDpiScale", img.Dpi.Scale.ToString("0.0", CultureInfo.InvariantCulture));

                copiedResources.Add(new TaskItem(itemSpec, attr));
            }

            CopiedResources = copiedResources.ToArray();

            return(System.Threading.Tasks.Task.CompletedTask);
        }