Exemple #1
0
        private static void BuildIcon(string filePath, int width, int height, byte[] imageBytes, int imageWidth,
                                      int imageHeight, int imageX, int imageY,
                                      Enums.ColorSelection tileIconifierColorSelection,
                                      string backgroundColor)
        {
            IoUtils.ForceDelete(filePath);
            using (var fs = new FileStream(filePath, FileMode.Create))
            {
                var outputBitmap = new Bitmap(width, height, PixelFormat.Format32bppArgb);

                var tempImage = ImageUtils.ByteArrayToImage(imageBytes);
                tempImage = ImageUtils.ScaleImage(tempImage, imageWidth, imageHeight);

                using (var graphics = Graphics.FromImage(outputBitmap))
                {
                    if (Config.StartMenuUpgradeEnabled && tileIconifierColorSelection != Enums.ColorSelection.Default)
                    {
                        var color = ColorUtils.HexOrNameToColor(backgroundColor);
                        graphics.Clear(color);
                    }
                    else
                    {
                        graphics.CompositingMode = CompositingMode.SourceCopy;
                    }
                    graphics.CompositingQuality = CompositingQuality.HighQuality;
                    graphics.InterpolationMode  = InterpolationMode.HighQualityBicubic;
                    graphics.SmoothingMode      = SmoothingMode.HighQuality;
                    graphics.PixelOffsetMode    = PixelOffsetMode.HighQuality;

                    graphics.DrawImage(tempImage,
                                       new PointF(imageX, imageY));
                }

                outputBitmap.Save(fs, ImageFormat.Png);
                outputBitmap.Dispose();
                tempImage.Dispose();
            }
        }
Exemple #2
0
 private static void BuildShortcutItemIcon(string fullIconPath, Size outputSize,
                                           ShortcutItemImage shortcutItemImage, XyRatio xyRatio, Enums.ColorSelection tileIconifierColorSelection, string backgroundColor)
 {
     BuildIcon(fullIconPath, outputSize.Width,
               outputSize.Height,
               shortcutItemImage.Bytes,
               (int)Math.Round(shortcutItemImage.Width * xyRatio.X, 0),
               (int)Math.Round(shortcutItemImage.Height * xyRatio.Y, 0),
               (int)Math.Round(shortcutItemImage.X * xyRatio.X, 0),
               (int)Math.Round(shortcutItemImage.Y * xyRatio.Y, 0),
               tileIconifierColorSelection,
               backgroundColor);
 }