Let's just say that is have a handle to an icon image in C#. Is there a way, to save the contents as a valid ICO file on disk? I have tried everything but no luck.
The first solution i thought was to create a Bitmap object based on the icon handle, and then save this Bitmap, to file as ico. The problem is that the implementation of .net does not work, and just outputs plain PNG data.
Then i tried implementing the encoder myself. Based on the header description of the ICO container, i implemented this, and works like a charm but only if i use png data as the payload.
If i use bitmap data(which is what is want) the output file does not get recognized by the OS as valid .ico file.
I am 99% sure that the problem is the way i write the bitmap data to the ICO container.
Based on an article i found that when the format in the ico file is PNG image it must be written along with the PNG header. If it is a bitmap image one must only write the raw data of the bitmap without the bitmap header.
Well, what i tried is to get the bitmap data (as byte array) using Lockbits() function of the Bitmap object and write, those after the ico header, and saving the file. I am sure that i had written the headers correctly. But i think that i am missing something, else
What is the correct way to write bitmap data to ico file?? Also, i wonder if there is another solution to write contents of an HICON(INtPtr in C#) handle to ico file.