GIDForums  

Go Back   GIDForums > Computer Programming Forums > .NET Forum
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 15-May-2009, 10:01
fakepoo fakepoo is offline
Regular Member
 
Join Date: Oct 2007
Posts: 713
fakepoo is a jewel in the roughfakepoo is a jewel in the roughfakepoo is a jewel in the rough

Convert a bitmap file to an icon file


I have a bitmap that I would like to display in a Windows form as an icon. I need to convert it to an icon before I can use it. The best solution that I have found is:

C-SHARP / C# Code:
                string bitmapFileName = openFileDialog1.FileName;

                // Retrieve the bitmap from the file.
                Bitmap bmp = (Bitmap)Image.FromFile(bitmapFileName);

                // Convert the bitmap to an icon.
                Icon ico = Icon.FromHandle(bmp.GetHicon());

                // Generate the icon file name
                string iconFileName = bitmapFileName.Remove(bitmapFileName.Length - 4) + ".ico";

                // Create a file stream to save the icon stream.
                Stream st = new FileStream(iconFileName, FileMode.Create);

                // Create a stream writer to physical write the data to the disk.
                BinaryWriter wr = new BinaryWriter(st);

                // Write the binary icon data to the file stream.
                ico.Save(st);

                // Close the file to write the stream to the disk.
                wr.Close();
The problem with this is that I lose all of the color and get a gray icon. Does anyone know of a better way to do this (in code or a separate application like paint)?

Thanks,
fakepoo
  #2  
Old 19-May-2009, 15:21
fakepoo fakepoo is offline
Regular Member
 
Join Date: Oct 2007
Posts: 713
fakepoo is a jewel in the roughfakepoo is a jewel in the roughfakepoo is a jewel in the rough

Re: Convert a bitmap file to an icon file


Just to follow up, there is a plugin available for Adobe Photoshop that supports saving icon files. That is what I used and it worked just fine.
 
 

Recent GIDBlogOnce again, no time for hobbies by crystalattice

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Power Calibration Error In Nero Fix (hopefully) matt3678 Computer Hardware Forum 60 20-Aug-2009 06:04
Airport Log program using 3D linked List : problem reading from file batrsau C Programming Language 11 29-Feb-2008 08:44
How to use the data obtain in one C file to another C file? TommyC C Programming Language 12 15-Jan-2008 10:51
After execution - Error cannot locate /Skin File? WSCH C++ Forum 1 05-Mar-2005 21:03
CD Buring Failed skanth2000 Computer Hardware Forum 1 15-Nov-2003 04:52

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 21:36.


vBulletin, Copyright © 2000 - 2009, Jelsoft Enterprises Ltd.