Convert a bitmap to an icon in compact framework for ppc2003

Hi Everyone,
	I am trying to convert a imagelist image (a bitmap) to an icon so that I can use 
the graphics class to draw it with transparency. However I cannot work out how to convert 
a bitmap into an icon - I've found samples like this:
 
Bitmap bitmap = new Bitmap(16, 16);
[..]
 Icon icon = Icon.FromHandle(bitmap.GetHicon());
But this doesn't work as GetHicon is not supported in the CF.
 
Any suggestions 
 
Regards
 
Mike Oleary
 


Answer this question

Convert a bitmap to an icon in compact framework for ppc2003

  • CSWong

    I know where you are coming from - but my point is that I have added an ICON to the imagelist - not a bitmap. Its the imagelist that is converting it internally (not me!) - now during this conversion it knows I added an icon and it would be quite possible to store what the transparency color was - as icons do support transparency. Now what I was wondering is if I could request back an icon (which is what I added in the first place) - if it was capable of returning what it was given ..... in your train of thought I would agree with you but the point is that it was an ICON to start with - not a bitmap.


  • AnnNeedsHelp

    Why do you believe icon would fix your transparency issue What kind of issue

    Most common transparency problem is what transparent color does not match color in bitmap since it was converted to 16 or 15 bit screen format.



  • Leo Ng

    .NETCF 1.0 or 2.0

    If you're in 2.0 I believe you can use Bitmap.Save to save the image as System.Drawing.Imaging.ImageFormat.Icon then construct the icon from your new file.

    http://msdn2.microsoft.com/en-us/library/9t4syfhh.aspx


  • DKB

    Unfortunately I am not starting a small application from scratch and have 10's of thousands of lines of legacy code to deal with as well - what I thought would be a quick fix is obviously not going to be. So I may end up having to use an array list instead - however I was trying to avoid this as it will have other flow on effects that are not insignificant.


  • BubbaHasty

    Are you saying you have icons initially, not bitmaps That makes even less sense, so let me get it strait:

    1. You have icon.

    2. You add it to image list.

    3. It's converted to bitmap internally.

    4. You convert that bitmap to icon.

    5. You use icon (because of transparency).

    If so, why don't we cut few steps out of it:

    1. You have icon.

    2. You use that icon.

    How's that Simply drop the image list and store icons in, say, array list instead.



  • AtMyWittsEnd

    Hi Ilya,

    Whilst I agree with some of your comments the icons are loaded from the disk that can be changed by an end user - so I cannot specify a predetermined transparency color. The icon is then added to the imagelist and it's the imagelist that converts it to a bitmap. However on the desktop you can convert it back to an icon using the code at the start of this post - therefor I assume there is a way of doing it......I am just missing the function on the netcf. An icon can infer transparency so I don't think I am asking for the impossible.


  • best49erfan

    I see...Let’s think if it’s going to work…

    You expect bitmap to icon converter would be able to infer transparency color for each picture somehow without you providing it How that would work Some sophisticated statistical image analysis which would conclude color X is the transparency color in this particular bitmap

    Or, perhaps, it will be more realistic to expect it would just grab pixels from original bitmap, scale that down to icon size and create useless (for your purposes) icon without any transparency mask (which you probably mean by “automatic transparency”)

    Also, would you agree what writing that “intelligent” bitmap to icon converter (which, as you already know, is not available on NETCF and, I suspect, desktop) would be quite a bit harder than simply specifying transparency colors Is it really that hard to store these colors somehow or convert all your bitmaps to use same color



  • Rhubarb

    And yet it’s probably better than a hack you’ve been about to introduce. Not to mention that hack could not possibly work even on desktop since after icon is converted to bitmap transparency mask is lost and converting bitmap back to icon won’t restore it.

    Anyway, good luck in your ArrayList modifications.



  • Mike Teperman

    With a bitmap you need to specify what the transparency color is - and in our application this could be different accross each picture....so too hard. With an icon it knows the transparency automatically - so removes this issue.


  • KippV

    Why don't you try it and see if desktop would indeed "infers" transparency color I would suggest the following simple test:

    1. Create test bitmap - half white/half black rectangle.

    2. Assume (in your mind – that’s what end user meant) transparency color is white.

    3. Do conversion to icon.

    4. Make sure icon’s transparency color is correctly set.

    5. Assume (in your mind – that’s what end user meant) transparency color is black.

    6. Do conversion to icon.

    7. Make sure icon’s transparency color is correctly set.



  • markand

    Hi,

    I am using .net 2 but the save method does not include a icon format option .....it supports all the common formats except icon :(


  • Convert a bitmap to an icon in compact framework for ppc2003