Exemple #1
0
 private void Export_Click(object sender, EventArgs e)
 {
     if (Icons.SelectedItems.Count > 0 && SaveTo.ShowDialog() == DialogResult.OK)
     {   // Collect all checked items from the Export menu and parse into an array of width x length sizes.
         var sizes = Array.ConvertAll(Choices(ExportAs.DropDownItems),
                                      item => Parse(item.Text.Replace("&", string.Empty).ToLowerInvariant().Trim()));
         foreach (ListViewItem selection in Icons.SelectedItems)
         {
             SingleIcon icon = (new MultiIcon()).Add(selection.Text);
             foreach (var size in sizes)
             {
                 icon.Add(imageMso[selection.Text, size[0], size[1]]);
             }
             icon.Save(Path.Combine(SaveTo.SelectedPath, string.Format("{0}.{1}", selection.Text, "ico")));
             DestroyIcon(icon.Icon.Handle);
         }
         MessageBox.Show("Export Complete.", "Export", MessageBoxButtons.OK, MessageBoxIcon.Information);
     }
 }
Exemple #2
0
 private void Save_Click(object sender, EventArgs e)
 {
     if (Icons.SelectedItems.Count > 0 && SaveTo.ShowDialog() == DialogResult.OK)
     {   // Collect all checked items from the Save menu and parse into an array of image formats.
         var formats = Array.ConvertAll(Choices(SaveAs.DropDownItems), item => Format(item.Name));
         var size    = Parse(Pixels.Text.ToLowerInvariant().Trim());
         foreach (ListViewItem selection in Icons.SelectedItems)
         {
             using (var image = imageMso[selection.Text, size[0], size[1]])
                 using (var canvas = new Bitmap(size[0], size[1]))
                     using (var drawing = Graphics.FromImage(canvas))
                     { // Image is drawn on a colored opaque canvas for formats that do not support transparency.
                         drawing.Clear(Palette.Color);
                         drawing.DrawImage(image, 0, 0);
                         foreach (ImageFormat format in formats)
                         {
                             string filename = Path.Combine(SaveTo.SelectedPath,
                                                            string.Format("{0}.{1}", selection.Text, Extension(format)));
                             if (format == ImageFormat.Icon)
                             { // image.Save(filename, format); // Loses color depth. Use IconLib instead.
                                 SingleIcon icon = (new MultiIcon()).Add(selection.Text);
                                 icon.Add(image);
                                 icon.Save(filename);
                                 DestroyIcon(icon.Icon.Handle);
                             }
                             else if (format == ImageFormat.Bmp || format == ImageFormat.Gif || format == ImageFormat.Jpeg)
                             {
                                 canvas.Save(filename, format); // These formats do not support alpha channel transparency.
                             }
                             else
                             {
                                 image.Save(filename, format);
                             }
                         }
                     }
         }
         MessageBox.Show("Save Complete.", "Save", MessageBoxButtons.OK, MessageBoxIcon.Information);
     }
 }