locked
how to decode icon

    Question

  • Hi,

    We are moving the server side of our app to a store app and I'm hoping someone can advise how best to proceed with processing icons.  The client side is currently sending byte arrays containing the hbmMask and hbmColor parts of an ICONINFO structure.  When the desktop version of the server app receives these it calls CreateIconIndirect, DrawIcon etc.

    I'm looking for the equivalent of CreateIconDirect.  BitmapDecoder using an IcoDecoderId appears to be the way to go but that decoder is expecting a ico file format, so my questions:

    1) Is this the best way to go about this?

    2) Assuming yes, how can I convert the mask and color bitmaps to an ico file format.  Looking at

    https://msdn.microsoft.com/en-us/library/ms997538.aspx

    I'll need to write an ICONDIR, ICONDIRENTRY and ICONIMAGE to a stream to pass to the decoder.  How do I create the ICONIMAGE from the mask and color values I have from ICONINFO, each of which have their own BITMAPINFOHEADER?

    Thanks for all the help, much appreciated. 

    Thursday, May 07, 2015 1:39 PM

All replies

  • There is no support for encoding ICOs in Windows Store apps. You'll need to handle the file format yourself: lay it out and then write those bytes to disk. In addition to John's article you can take a look at Raymond Chen's series The evolution of the ICO file format:

    Roughly speaking, the icon is stored as the BITMAPINFOHEADER followed by the color table followed by the  icon pixels followed by the mask pixels.

    Friday, May 08, 2015 1:55 AM
    Owner
  • Thanks Rob,  

    I'm not trying to encode ICOs, I want to decode the ICO data I have (mask and color from ICONINFO) and convert into another format, so I assume I need to decode ico (using BitmapDecoder icodecoderid) and then reencode (uing BitmapEncoder).

    However I assume icodecoderid expects a full file format in which case I need the equivalent of CreateIconIndirect.

    Thanks

    Friday, May 08, 2015 3:23 PM
  • It sounds like you have an XY Problem: you literally asked how to encode an ICO, but it sounds like that's just an extraneous step along the way to your real goal.

    Windows Runtime apps don't use HICONs and so don't have an equivalent of CreateIconIndirect (which returns an HICON, not an icon file). Pretty much the only place where Windows Runtime apps touch icons is in the BitmapDecoder's ability to read one in and decode it to a bitmap.

    If you're just trying to convert the bitmap information that you already have in the mask and color planes (as described by the BITMAPINFOHEADER) into a bitmap then you can do that directly without converting back to an ICO first.

    Saturday, May 09, 2015 1:33 AM
    Owner
  • Thanks Rob, could you give a little more help on how I would do the last bit, load the mask and color planes into a bitmap.

    Saturday, May 09, 2015 7:39 AM