private void btnPickFile_Click(object sender, EventArgs e) { var result = iconPickerDialog.ShowDialog(this); if (result == DialogResult.OK) { var fileName = iconPickerDialog.FileName; m_iconIndex = iconPickerDialog.IconIndex; Icon icon = null; Icon[] splitIcons = null; try { if (Path.GetExtension(iconPickerDialog.FileName).ToLower() == ".ico") { m_iconExtractor = null; icon = new Icon(iconPickerDialog.FileName); } else { m_iconExtractor = new IconExtractor(fileName); icon = m_iconExtractor.GetIcon(m_iconIndex); } splitIcons = IconUtil.Split(icon); } catch (Exception ex) { MessageBox.Show(ex.Message, Text, MessageBoxButtons.OK, MessageBoxIcon.Error); return; } txtFileName.Text = String.Format( "{0}, #{1}, {2} variations", fileName, m_iconIndex, splitIcons.Length); // Update icons. Icon = icon; icon.Dispose(); lvwIcons.BeginUpdate(); ClearAllIcons(); foreach (var i in splitIcons) { var item = new IconListViewItem(); var size = i.Size; item.BitCount = IconUtil.GetBitCount(i); item.Bitmap = IconUtil.ToBitmap(i); item.ToolTipText = String.Format("{0}x{1}, {2} bits", size.Width, size.Height, item.BitCount); i.Dispose(); lvwIcons.Items.Add(item); } lvwIcons.EndUpdate(); btnSaveAsIco.Enabled = (m_iconExtractor != null); } }
private void bw_DoWork(object sender, DoWorkEventArgs e) { var ie = new TsudaKageyu.IconExtractor(tbLibrary.Text); var i = 0; this._Icons = ie.GetAllIcons().Select(s => new IconFile() { Icon = s, Index = i++ }).ToList(); }
private void LoadIcons(object Params) { Invoke(new MethodInvoker( delegate { lvIcons.BeginUpdate(); lvIcons.Items.Clear(); var ie = new TsudaKageyu.IconExtractor(tbLibrary.Text); var i = 0; _Icons = ie.GetAllIcons().Select(s => new IconFile() { Icon = s, Index = i++ }).ToList(); foreach (var icon in _Icons) { lvIcons.Items.Add(new ListViewItem("#" + icon.Index.ToString()) { Tag = icon.Index }); } lvIcons.EndUpdate(); })); }
private static Task<Bitmap> ExtractIcon(string path, string name, int index = 0) { return Task.Run(() => { if (!File.Exists(path)) return null; try { var extractor = new IconExtractor(path); var icon = extractor.GetIcon(index); return new Icon(icon, new Size(16, 16)).ToBitmap(); } catch (Exception e) { Debug.WriteLine("Failed to load icon for " + name + ": " + e); return null; } }); }