Example #1
0
 private void btnExport_Click(object sender, EventArgs e)
 {
     dlgSave.DefaultExt = "icl";
     dlgSave.Filter     = "Windows Icon File (*.ico)|*.ico|Icon Library File (*.icl)|*.icl|DLL Library File " +
                          "(*.dll)|*.dll|PNG Image File (*.png)|*.png|BMP Windows File (*.bmp)|*.bmp";
     if (dlgSave.ShowDialog(this) == DialogResult.OK)
     {
         if (dlgSave.FileName.ToLower().EndsWith(".ico") && mMultiIcon.SelectedIndex != -1)
         {
             mMultiIcon.Save(dlgSave.FileName, MultiIconFormat.ICO);
         }
         else if (dlgSave.FileName.ToLower().EndsWith(".png") && mMultiIcon.SelectedIndex != -1 && lbxImages.SelectedIndex != -1)
         {
             mMultiIcon[mMultiIcon.SelectedIndex][lbxImages.SelectedIndex].Transparent.Save(dlgSave.FileName, ImageFormat.Png);
         }
         else if (dlgSave.FileName.ToLower().EndsWith(".bmp") && mMultiIcon.SelectedIndex != -1 && lbxImages.SelectedIndex != -1)
         {
             mMultiIcon[mMultiIcon.SelectedIndex][lbxImages.SelectedIndex].Transparent.Save(dlgSave.FileName, ImageFormat.Bmp);
         }
         else if (dlgSave.FileName.ToLower().EndsWith(".icl"))
         {
             mMultiIcon.Save(dlgSave.FileName, MultiIconFormat.ICL);
         }
         else if (dlgSave.FileName.ToLower().EndsWith(".dll"))
         {
             mMultiIcon.Save(dlgSave.FileName, MultiIconFormat.DLL);
         }
     }
 }
Example #2
0
 /*
  * Extract Icon Function - used to extract icons by utilizing the IconLib Library.
  * ----------------------------------------------------------------------------------
  * extractIcon(
  *      From button Boolean Value (bool),
  *      File to extract the Icon from (string)
  * )
  * ----------------------------------------------------------------------------------
  * fromButton suppresses error if it wasn't the users' intention to extract an icon
  * returns: nothing
  */
 private void extractIcon(bool fromButton = false, string iconfile = "")
 {
     if (excomp[0] && iconfile != "")
     {
         dbgmsg("Extracting associated icon to bitmap...");
         (Icon.ExtractAssociatedIcon(iconfile).ToBitmap()).Save(apth + "\\$_bmptmp.bmp");
         MultiIcon conico = new MultiIcon();
         conico.Add("iconinstance").CreateFrom(apth + "\\$_bmptmp.bmp", IconOutputFormat.Vista);
         conico.SelectedIndex = 0;
         conico.Save(apth + "\\$tmp.ico", MultiIconFormat.ICO);
         imgFileIcon.ImageLocation = "$tmp.ico";
         File.Delete(apth + "\\$_bmptmp.bmp");
         dbgmsg("Temporary bitmap file deleted.");
         isicon = true;
     }
     else
     {
         if (fromButton)
         {
             MessageBox.Show("No spoof file imported or Icon Library functions can't be utilized", "Error", MessageBoxButtons.OK, MessageBoxIcon.Warning);
         }
         else
         {
             dbgmsg("Error from un-intended extraction suppressed!");
         }
     }
 }
Example #3
0
 public void Convert(Bitmap bitmap, string icoPath)
 {
     MultiIcon mIcon = new MultiIcon();
     mIcon.Add("Untitled").CreateFrom(bitmap, IconOutputFormat.Vista);
     mIcon.SelectedIndex = 0;
     mIcon.Save(icoPath, MultiIconFormat.ICO);
 }
Example #4
0
        public static void Convert(Bitmap bitmap, string icoPath)
        {
            var mIcon = new MultiIcon();

            mIcon.Add("Untitled").CreateFrom(bitmap, IconOutputFormat.Vista);
            mIcon.SelectedIndex = 0;
            mIcon.Save(icoPath, MultiIconFormat.ICO);
        }
Example #5
0
 public void CreateIcon(string name,string source, string destination)
 {
     MultiIcon icon = new MultiIcon();
     SingleIcon single = icon.Add(name);
     single.CreateFrom(source, IconOutputFormat.FromWinXP);
     icon.SelectedIndex = 0;
     icon.Save(destination, MultiIconFormat.ICO);
 }
Example #6
0
        public void CreateIcon(string name, string source, string destination)
        {
            MultiIcon  icon   = new MultiIcon();
            SingleIcon single = icon.Add(name);

            single.CreateFrom(source, IconOutputFormat.FromWinXP);
            icon.SelectedIndex = 0;
            icon.Save(destination, MultiIconFormat.ICO);
        }
        protected bool CreateShortcutIcon()
        {
            // Skip if a suitable icon file already exists
            var originalPath = GetShortcutIconPath();

            if (File.Exists(originalPath))
            {
                var bytes = new byte[4];
                using (var file = File.OpenRead(originalPath))
                {
                    file.Read(bytes, 0, 4);
                }
                if (bytes[0] == 0 && bytes[1] == 0 && bytes[2] == 1 && bytes[3] == 0)
                {
                    return(true);
                }
                using (var img = new Bitmap(originalPath))
                {
                    var extension = ImageCodecInfo.GetImageDecoders().FirstOrDefault(dec => dec.FormatID == img.RawFormat.Guid)?.FilenameExtension.Replace("*", string.Empty).ToLower().Split(';');
                    if (extension != null)
                    {
                        if (!extension.Contains(Path.GetExtension(originalPath).ToLower()))
                        {
                            FixWrongIconExtension(originalPath, img);
                        }
                    }
                }
            }

            string gameIconPath = GetGameIconPath();

            if (File.Exists(gameIconPath))
            {
                using (Bitmap bitmap = new Bitmap(gameIconPath))
                {
                    Size iconSize = new Size(256, 256);
                    using (Bitmap resized = new Bitmap(iconSize.Width, iconSize.Height))
                    {
                        using (Graphics g = Graphics.FromImage(resized))
                        {
                            g.DrawImage(bitmap, 0, 0, iconSize.Width, iconSize.Height);
                        }

                        MultiIcon  mIcon = new MultiIcon();
                        SingleIcon sIcon = mIcon.Add("Original");
                        sIcon.CreateFrom(resized, IconOutputFormat.FromWin95);
                        mIcon.SelectedIndex = 0;
                        mIcon.Save(GetShortcutIconPath(), MultiIconFormat.ICO);
#if DEBUG
                        // if (File.Exists(GetGameIconPath())) throw new Exception($"{GetShortcutIconPath()} was not created!");
#endif
                        return(true);
                    }
                }
            }
            return(false);
        }
Example #8
0
 private void btnExport_Click(object sender, EventArgs e)
 {
     dlgSave.DefaultExt = "icl";
     dlgSave.Filter     = "PNG Image File (*.png)|*.png|Windows Icon File (*.ico)|*.ico|Icon Library File (*.icl)|*.icl|DLL Library File " +
                          "(*.dll)|*.dll|BMP Windows File (*.bmp)|*.bmp";
     if (dlgSave.ShowDialog(this) == DialogResult.OK)
     {
         if (dlgSave.FileName.ToLower().EndsWith(".ico") && mMultiIcon.SelectedIndex != -1)
         {
             mMultiIcon.Save(dlgSave.FileName, MultiIconFormat.ICO);
         }
         else if (dlgSave.FileName.ToLower().EndsWith(".png") && mMultiIcon.SelectedIndex != -1 && lbxImages.SelectedIndex != -1)
         {
             Bitmap iconBmp = mMultiIcon[mMultiIcon.SelectedIndex][lbxImages.SelectedIndex].Transparent;
             if (this.radioButton2.Checked)
             {
                 // convert it to the specified size
                 iconBmp = BitmapFineResize(iconBmp,
                                            new Size((int)numericUpDown1.Value, (int)numericUpDown2.Value));
             }
             iconBmp.Save(dlgSave.FileName, ImageFormat.Png);
         }
         else if (dlgSave.FileName.ToLower().EndsWith(".bmp") && mMultiIcon.SelectedIndex != -1 && lbxImages.SelectedIndex != -1)
         {
             Bitmap iconBmp = mMultiIcon[mMultiIcon.SelectedIndex][lbxImages.SelectedIndex].Transparent;
             if (this.radioButton2.Checked)
             {
                 // convert it to the specified size
                 iconBmp = BitmapFineResize(iconBmp,
                                            new Size((int)numericUpDown1.Value, (int)numericUpDown2.Value));
             }
             iconBmp.Save(dlgSave.FileName, ImageFormat.Bmp);
         }
         else if (dlgSave.FileName.ToLower().EndsWith(".icl"))
         {
             mMultiIcon.Save(dlgSave.FileName, MultiIconFormat.ICL);
         }
         else if (dlgSave.FileName.ToLower().EndsWith(".dll"))
         {
             mMultiIcon.Save(dlgSave.FileName, MultiIconFormat.DLL);
         }
     }
 }
Example #9
0
 private void btnCreate_Click(object sender, EventArgs e)
 {
     MultiIcon multiIcon = new MultiIcon();
     multiIcon.Add("Icon 1").Load(Path.Combine(Path.GetDirectoryName(Application.ExecutablePath), "Icon1.ico"));
     multiIcon.Add("Icon 2").Load(Path.Combine(Path.GetDirectoryName(Application.ExecutablePath), "Icon2.ico"));
     multiIcon.Add("Icon 3").Load(Path.Combine(Path.GetDirectoryName(Application.ExecutablePath), "Icon3.ico"));
     multiIcon.Add("Icon 4").Load(Path.Combine(Path.GetDirectoryName(Application.ExecutablePath), "Icon4.ico"));
     multiIcon.Add("Icon 5").Load(Path.Combine(Path.GetDirectoryName(Application.ExecutablePath), "Icon5.ico"));
     multiIcon.Add("Icon 6").Load(Path.Combine(Path.GetDirectoryName(Application.ExecutablePath), "Icon6.ico"));
     multiIcon.Add("Icon 7").Load(Path.Combine(Path.GetDirectoryName(Application.ExecutablePath), "Icon7.ico"));
     multiIcon.Save(Path.Combine(Path.GetDirectoryName(Application.ExecutablePath),"library.icl"), MultiIconFormat.ICL);
 }
Example #10
0
        private void btnCreate_Click(object sender, EventArgs e)
        {
            MultiIcon multiIcon = new MultiIcon();

            multiIcon.Add("Icon 1").Load(Path.Combine(Path.GetDirectoryName(Application.ExecutablePath), "Icon1.ico"));
            multiIcon.Add("Icon 2").Load(Path.Combine(Path.GetDirectoryName(Application.ExecutablePath), "Icon2.ico"));
            multiIcon.Add("Icon 3").Load(Path.Combine(Path.GetDirectoryName(Application.ExecutablePath), "Icon3.ico"));
            multiIcon.Add("Icon 4").Load(Path.Combine(Path.GetDirectoryName(Application.ExecutablePath), "Icon4.ico"));
            multiIcon.Add("Icon 5").Load(Path.Combine(Path.GetDirectoryName(Application.ExecutablePath), "Icon5.ico"));
            multiIcon.Add("Icon 6").Load(Path.Combine(Path.GetDirectoryName(Application.ExecutablePath), "Icon6.ico"));
            multiIcon.Add("Icon 7").Load(Path.Combine(Path.GetDirectoryName(Application.ExecutablePath), "Icon7.ico"));
            multiIcon.Save(Path.Combine(Path.GetDirectoryName(Application.ExecutablePath), "library.icl"), MultiIconFormat.ICL);
        }
Example #11
0
        private Icon ConvertToIcon(Bitmap image)
        {
            var converted = new MemoryStream();
            var multi     = new MultiIcon();
            var icon      = multi.Add("Main");

            icon.CreateFrom(image, IconOutputFormat.Vista);
            multi.SelectedIndex = 0;
            multi.Save(converted, MultiIconFormat.ICO);

            converted.Seek(0, SeekOrigin.Begin);
            return(new Icon(converted));
        }
        private void buttonConvert_Click(object sender, EventArgs e)
        {
            try
            {
                MultiIcon  mIcon = new MultiIcon();
                SingleIcon sIcon = mIcon.Add("Icon1");

                string pngPath = textPngPath.Text;
                string icoPath = textIcoPath.Text;

                sIcon.CreateFrom(pngPath, IconOutputFormat.FromWinXP);
                mIcon.SelectedIndex = 0;
                mIcon.Save(icoPath, MultiIconFormat.ICO);
            }
            catch (Exception ex)
            {
                alert($"Err={ex}");
            }
        }
Example #13
0
        private void btn_Make_Click(object sender, EventArgs e)
        {
            using (SaveFileDialog sfd = new SaveFileDialog())
            {
                sfd.FileName = "untitled.ico";
                if (sfd.ShowDialog() == DialogResult.OK)
                {
                    MultiIcon  icons = new MultiIcon();
                    SingleIcon si    = icons.Add("pack");
                    icons.SelectedName = "pack";
                    foreach (string item in lst_Images.Items)
                    {
                        var newImage = new Bitmap(Bitmap.FromFile(item));
                        if (newImage.Width > 256 || newImage.Height > 256)
                        {
                            MessageBox.Show($"icon with size larger than 256px width or 256px height cannot be added");
                            continue;
                        }
                        bool notExist = true;
                        foreach (var ei in si)
                        {
                            if (ei.Size.Width == newImage.Width && ei.Size.Height == newImage.Height)
                            {
                                notExist = false;
                            }
                        }
                        if (notExist)
                        {
                            si.Add(newImage);
                        }
                        else
                        {
                            MessageBox.Show($"icon with same size cannot be added\r\nkeep one of images with size{newImage.Width}*{newImage.Height}");
                        }
                    }


                    icons.Save(sfd.FileName, MultiIconFormat.ICO);
                }
            }
        }
Example #14
0
        public static void Main(string[] args)
        {
            if (args.Length < 1)
            {
                Console.WriteLine("Usage: IcoPngCombine.exe [start_folder]");
                Console.WriteLine("Start folder should contain this directory/file structure:");
                Console.WriteLine("    size\\category\\icon_name.png");
                Console.WriteLine("Like you can see in this repo: https://github.com/KDE/oxygen-icons");
                Console.WriteLine("This tool creates a \"results\" folder in the start folder and puts all of the combined icons there");

                return;
            }

            string startFolder = args[0];

            if (!Directory.Exists(startFolder))
            {
                Console.Error.WriteLine($"Directory {startFolder} doesn't exist.");

                return;
            }

            string results = Path.Combine(startFolder, "results");

            Directory.CreateDirectory(results);

            string[] sizes = Directory.GetDirectories(startFolder);

            HashSet <string> createdIcons = new HashSet <string>();

            foreach (string scannedSize in sizes)
            {
                string[] categories = Directory.GetDirectories(scannedSize);
                foreach (string category in categories)
                {
                    string catName = Path.GetFileName(category);

                    string[] icons = Directory.GetFiles(category, "*.png");
                    foreach (string icon in icons)
                    {
                        string iconFileName = Path.GetFileName(icon);
                        string iconName     = Path.GetFileNameWithoutExtension(icon);

                        string iconFullPath = Path.Combine(catName, iconFileName);
                        string iconId       = Path.Combine(catName, iconName);

                        if (createdIcons.Contains(iconId))
                        {
                            continue;
                        }

                        createdIcons.Add(iconId);

                        MultiIcon     img = new MultiIcon();
                        int           index = -1, selectedIndex = -1, selectedIndexSize = 0;
                        List <string> szs = new List <string>();
                        foreach (string sz in sizes)
                        {
                            string fullPath = Path.Combine(sz, iconFullPath);
                            if (!File.Exists(fullPath))
                            {
                                continue;
                            }

                            string sizeName = Path.GetFileName(sz);

                            SingleIcon ic = img.Add(sizeName);

                            try
                            {
                                Bitmap bmp = (Bitmap)Bitmap.FromFile(fullPath);

                                try
                                {
                                    ic.CreateFrom(bmp, IconOutputFormat.Vista);

                                    szs.Add(sizeName);

                                    index += 1;
                                    if (!Int32.TryParse(new String(sizeName.TakeWhile(c => c >= '0' && c <= '9').ToArray()), out int size))
                                    {
                                        size = 0;
                                    }

                                    if (selectedIndex < 0 || selectedIndexSize < size)
                                    {
                                        selectedIndex     = index;
                                        selectedIndexSize = size;
                                    }
                                }
                                catch (ImageTooBigException)
                                {
                                    Console.WriteLine($"Image {sizeName}\\{iconId} has dimensions that are too big: w={bmp.Width}, h={bmp.Height}");

                                    img.Remove(ic);
                                }
                            }
                            catch (InvalidPixelFormatException ex)
                            {
                                Console.WriteLine($"Ignoring size {sizeName} of {iconId} because {ex.Message}, required is {PixelFormat.Format32bppArgb}");

                                img.Remove(ic);
                            }
                        }

                        if (selectedIndex < 0)
                        {
                            continue;
                        }

                        string dirName = Path.Combine(results, catName);
                        if (!Directory.Exists(dirName))
                        {
                            Directory.CreateDirectory(dirName);
                        }

                        img.SelectedIndex = selectedIndex;

                        Console.WriteLine($"Saving {iconId} with sizes [{String.Join(", ", szs)}]");

                        string icoName = Path.Combine(results, iconId) + ".ico";
                        img.Save(icoName, MultiIconFormat.ICO);
                    }
                }
            }

            Console.WriteLine($"Done. Created {createdIcons.Count} icons.");
        }