views:

1380

answers:

3

The title of the question pretty much states the problem. Is it possible?

+2  A: 

We had this problem a couple of months back and we found this solution

http://www.dreamincode.net/code/snippet1684.htm

I'm sooo glad that we insert references in our comments to where we found something. I prefer sending this to you instead of my code because it's merge with a get multiple zipped file which complexify what you really want to get at.

Philippe Asselin
This converts a System.Drawing.Image to a System.Drawing.Icon. I'm trying to convert a System.Windows.Control.Image to an System.Drawing.Icon.
Mark Schroering
+2  A: 

I modified an example from here. This seems to work pretty good.

    public static Icon Convert(BitmapImage bitmapImage)
    {
        System.Drawing.Bitmap bitmap = null;
        var width = bitmapImage.PixelWidth;
        var height = bitmapImage.PixelHeight;
        var stride = width * ((bitmapImage.Format.BitsPerPixel + 7) / 8);

        var bits = new byte[height * stride];

        bitmapImage.CopyPixels(bits, stride, 0);

        unsafe
        {
            fixed (byte* pB = bits)
            {
                var ptr = new IntPtr(pB);

                bitmap = new System.Drawing.Bitmap(width, height, stride,
                                                System.Drawing.Imaging.PixelFormat.Format32bppPArgb,
                                                ptr);
            }

        }

        return Icon.FromHandle(bitmap.GetHicon());
    }
Mark Schroering
A: 

how would you convert a system.drawing.image to a system.windows.controls.image? i need your help!!! =´(

virus