static void Main(string[] args) { using (Image bmp = Image.FromFile("target.bmp")) using (Bitmap newBmp = new Bitmap(bmp, new Size(48, 48))) using (Bitmap newFormatBmp = newBmp.Clone(new Rectangle(0, 0, newBmp.Width, newBmp.Height), PixelFormat.Format24bppRgb)) { // DestroyIcon(pntr); - dont need it. using (System.IO.Stream st = new System.IO.FileStream("final.ico", FileMode.Create)) { IntPtr pntr = newFormatBmp.GetHicon(); Icon nwico = Icon.FromHandle(pntr); System.IO.BinaryWriter wr = new System.IO.BinaryWriter(st); nwico.Save(st); } //create the final icon by writing in the temp one and then saving to hdd overwritting to it using (var Iconex = new IconEx("final.ico")) { Iconex.Items.RemoveAt(0); IconDeviceImage IcondeviceImage = new IconDeviceImage(new Size(48, 48), ColorDepth.Depth32Bit); IcondeviceImage.IconImage = new Bitmap(bmp); Iconex.Items.Add(IcondeviceImage); Iconex.Save("deviceImage.ico"); } } }
private void InstallationPromptForm_Load(object sender, EventArgs e) { Text = @$ "{_targetAssembly.Title}: prerequisites missing"; Icon = IconEx.TryExtractAssociatedIcon(Application.ExecutablePath); IconPictureBox.Image = SystemIcons.Warning.ToBitmap(); MissingPrerequisitesTextBox.Lines = _missingPrerequisites.Select(c => $"• {c.DisplayName}").ToArray(); }
private void InstallationForm_Load(object sender, EventArgs e) { Text = @$ "{_targetAssembly.Title}: installing prerequisites"; Icon = IconEx.TryExtractAssociatedIcon(Application.ExecutablePath); UpdateStatus(@"Preparing installation"); new Thread(PerformInstall) { Name = nameof(PerformInstall), IsBackground = true }.Start(); }
public static void SaveExeIcon(string exeFile, string iconFile) { IconEx iEx = null; try { iEx = new IconEx(exeFile, IDI_APPLICATION); iEx.Save(iconFile); } finally { if (iEx != null) { iEx.Dispose(); } } }
public ChartAreaValuesView() { InitializeComponent(); _errorProvider = new ErrorProvider(yNNumericUpDown); if (RuntimeInformation.IsWindows) { using (var icon = new IconEx(IconEx.SystemIcons.Error, _errorProvider.Icon.Size.DpiScale())) { _errorProvider.Icon = new Icon(icon.Icon, _errorProvider.Icon.Size.DpiScale()); } } _controlsByProperties = new Dictionary <string, Control>() { { nameof(XMin), x0NumericUpDown }, { nameof(XMax), xnNumericUpDown }, { nameof(YMin), y0NumericUpDown }, { nameof(YMax), yNNumericUpDown }, }; //presenter = new ChartAreaValuesPresenter(this); }
public void pieceDragSource_MouseDown(object sender, MouseEventArgs e) { // Start the drag if it's the left mouse button. if (e.Button == MouseButtons.Left) { PictureBox pb = (PictureBox)sender; float SquareWidth = 695 / 8; CurrentMove.fromCol = (int)pb.Location.X / (int)SquareWidth; CurrentMove.fromRow = (int)pb.Location.Y / (int)SquareWidth; if (pb.Image != null) { Image tempImage = pb.Image; pb.Image = null; Bitmap bm = new Bitmap(tempImage); IntPtr Hicon = bm.GetHicon(); dragCursor = new Cursor(Hicon); Cursor.Current = dragCursor; // This chunk is non-functional, but let's see if it does something eventually. Graphics graphics = this.CreateGraphics(); Rectangle rectangle = new Rectangle( new Point(10, 10), new Size(Cursor.Size.Width / 2, (int)Math.Floor(SquareWidth))); dragCursor.DrawStretched(graphics, rectangle); DragDropEffects drop = pb.DoDragDrop(tempImage, DragDropEffects.Move); var icon = new IconEx(Hicon, new Size(10, 10)); Cursor.Current = dragCursor; if (drop == DragDropEffects.None) { pb.Image = tempImage; } dragCursor.Dispose(); Cursor.Current = Cursors.Default; } } }
private static void ConvertToIco(Bitmap bmp, string outputFile, Settings settings) { File.Create(outputFile).Close(); IntPtr Hicon = bmp.GetHicon(); Icon newIcon = Icon.FromHandle(Hicon); FileStream fs = new FileStream(outputFile, FileMode.OpenOrCreate); newIcon.Save(fs); fs.Close(); IconDeviceImageCollection coll = new IconDeviceImageCollection(); using (IconEx iconex = new IconEx(outputFile)) { iconex.Items = new IconDeviceImageCollection(new IconDeviceImage[settings.Sizes.Count()]); if (settings.ReplaceColor) { Color orig = settings.OriginalColor; Color repl = settings.ReplacementColor; int tolerance = settings.ReplacementTolerance; using (Graphics g = Graphics.FromImage(bmp)) { #region RIP nicer solution /* * //Todo: I wish I could use this approach with the remap table, * //but sadly, I can't implement the tolerance with it * //and since I don't want to use unsave memory management code * //I'll have to use the slow as balls pixel by pixel recoloring... * ColorMap[] colorMap = new ColorMap[1]; * colorMap[0] = new ColorMap(); * colorMap[0].OldColor = orig; * colorMap[0].NewColor = repl; * ImageAttributes attr = new ImageAttributes(); * attr.SetRemapTable(colorMap); * // Draw using the color map * Rectangle rect = new Rectangle(0, 0, bmp.Width, bmp.Height); * g.DrawImage(bmp, rect, 0, 0, rect.Width, rect.Height, GraphicsUnit.Pixel, attr); */ #endregion for (int X = 0; X < bmp.Width; X++) { for (int Y = 0; Y < bmp.Height; Y++) { Color gp = bmp.GetPixel(X, Y); if ((gp.R >= orig.R - tolerance && gp.R <= orig.R + tolerance) && (gp.G >= orig.G - tolerance && gp.G <= orig.G + tolerance) && (gp.B >= orig.B - tolerance && gp.B <= orig.B + tolerance)) { bmp.SetPixel(X, Y, repl); } } } } } if (settings.Sizes.Count() == 0) { settings.Sizes = new Size[] { new Size(bmp.Width, bmp.Height) }; } foreach (Size size in settings.Sizes) { var icon = new IconDeviceImage(size, settings.ColorDepth); Bitmap newBmp = new Bitmap(size.Width, size.Height); using (Graphics g = Graphics.FromImage(newBmp)) { using (Graphics gg = Graphics.FromImage(bmp)) { g.DrawImage(bmp, new Rectangle(new Point(0, 0), size)); } } icon.IconImage = newBmp; coll.Add(icon); //iconex.Items.Add(icon); } iconex.Items.Capacity = coll.Count; iconex.Items.Clear(); foreach (var item in coll) { iconex.Items.Add((IconDeviceImage)item); } iconex.Save(outputFile); } }