This code will convert an Image to Icon using C#. It is written .Net Framework 3.5, but it should work in .Net 2.0. It supports Images upto size 128×128. And supports various image formats(*.jpg,*.gif, *.png. *.bmp).
using System; using System.Drawing; using System.IO; string fileName, newFileName; fileName = "C:\Sample.jpg"; newFileName = Path.ChangeExtension(fileName, ".ico"); using (Bitmap bitmap = Image.FromFile(fileName, true) as Bitmap) { using (Icon icon = Icon.FromHandle(bitmap.GetHicon())) { using (Stream imageFile = File.Create(newFileName)) { icon.Save(imageFile); Console.WriteLine("Converted - {0}", newFileName); } } }
|
No responses found. Be the first to respond and make money from revenue sharing program.
|