public static bool ExtractToIco(string iconSourcePath, int iconSourceIndex, string icoDestPath) { var success = false; var IconLoadError = false; if (!File.Exists(iconSourcePath)) { return(false); } var mIcon = new System.Drawing.IconLib.MultiIcon(); try { mIcon.Load(iconSourcePath); } catch (Exception) { IconLoadError = true; } if (IconLoadError) { return(success); } var sIcon = iconSourceIndex == 0 ? mIcon.FirstOrDefault() : mIcon[iconSourceIndex]; try { sIcon.Save(icoDestPath); success = true; } catch (Exception) { } return(success); }
private bool LoadIcons() { IconList.Clear(); SmallIcons.Images.Clear(); var IconError = false; IconIndexLabel.Visible = true; IconIndexTextBox.Visible = true; if (File.Exists(IconPathTextBox.Text)) { var mIcon = new System.Drawing.IconLib.MultiIcon(); var IconIndex = 0; try { mIcon.Load(IconPathTextBox.Text); IconIndexTextBox.ReadOnly = true; } catch (Exception) { IconError = true; _noValidate = true; OKButton.Enabled = true; MessageBox.Show("There was an error loading icons from:" + Environment.NewLine + IconPathTextBox.Text + Environment.NewLine + "Icons may still be usable, but you can not select one using the icon picker.", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); IconIndexTextBox.Text = "0"; IconIndexTextBox.ReadOnly = false; } if (!IconError) { _noValidate = false; foreach (var sIcon in mIcon) { var IconKey = IconIndex; var IconItem = new ListViewItem(IconKey.ToString()); var fiImage = sIcon[0]; foreach (var iImage in sIcon) { if (iImage.Icon.Width == 32) { switch (iImage.ColorsInPalette) { case 0: { fiImage = iImage; break; } default: { if (iImage.ColorsInPalette > fiImage.ColorsInPalette) { fiImage = iImage; } break; } } if (iImage.ColorsInPalette == 0) { fiImage = iImage; } } } var TheBitmap = fiImage.Icon.ToBitmap(); SmallIcons.Images.Add(IconKey.ToString(), TheBitmap); IconItem.ImageKey = IconKey.ToString(); IconList.Items.Add(IconItem); IconIndex++; } if (!_noValidate) { OKButton.Enabled = false; } } } return(IconError); }