Sunday, February 14, 2010

Convert image to icon in asp.net

string filename, newfilename;
filename= "E:/..../images/window.jpg"; // your image location
newfilename= Path.ChangeExtension(filename, ".ico");
using(Bitmap bitmap = Image.FromFile(filename, true) as Bitmap)
{
using (Icon icon = Icon.FromHandle(bitmap.GetHicon()))
{
using (Stream iconfile = File.Create(newfilename))
{
icon.Save(iconfile);
Response.Write("Converted - " + newfilename);
}
}
}

Note: Get an icon file n the same folder of image with extension'.ico', it may not work properly,
if the file size morethan 120X120. Try to choose small images.

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home