Bonjour @ tous,

J'ai essayé beaucoup de choses, mais rien ne fonctionne.
J'ai une image chargée depuis une source externe.
Elle m'arrive chargée dans un type System.Drawing.Image.

J'aimerais la mettre dans un MenuItem.Icon, mais rien n'y fait.

Voici mes tests:
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
                    if ((fct!=null) && (ImgConv.CanConvertFrom(clsGlobal.Env.GetIconFromRessources(fct.Icone).GetType()))) {                        
                        var img = ((System.Drawing.Image)ImgConv.ConvertFrom(clsGlobal.Env.GetIconFromRessources(fct.Icone)));
                        //ic.Icon = new System.Windows.Controls.Image { Source = newBitmapImage(newUri(“/ Images / icon_edit.png”, UriKind.Relative)) };
                        //ic.Icon = new System.Windows.Controls.Image { Source = new System.Windows.Media.Imaging.BitmapImage() { StreamSource = img.ToImageSource()} };
                    }
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
        public static ImageSource ToImageSource(this System.Drawing.Icon pIcon) {
            ImageSource ret = System.Windows.Interop.Imaging.CreateBitmapSourceFromHIcon(pIcon.Handle, Int32Rect.Empty, System.Windows.Media.Imaging.BitmapSizeOptions.FromEmptyOptions());
            return ret;
        }
        public static System.Windows.Media.Imaging.BitmapImage ToBitmapImage(this System.Drawing.Image pImg) {
            System.Windows.Media.Imaging.BitmapImage bi = new System.Windows.Media.Imaging.BitmapImage();
            bi.BeginInit();
            MemoryStream ms = new MemoryStream();            
            pImg.Save(ms, System.Drawing.Imaging.ImageFormat.Bmp);// Save to a memory stream... 
            ms.Seek(0, SeekOrigin.Begin);// Rewind the stream...
            bi.StreamSource = ms; // Tell the WPF image to use this stream...
            bi.EndInit();
            return bi; // */
 
            //var decoder = System.Windows.Media.Imaging.BitmapDecoder.Create(ms, System.Windows.Media.Imaging.BitmapCreateOptions.PreservePixelFormat, System.Windows.Media.Imaging.BitmapCacheOption.OnLoad);
            //return decoder.Frames[0];
 
            /*System.Drawing.Bitmap newBitmap = new System.Drawing.Bitmap(pImg);
            ImageSource ret = System.Windows.Interop.Imaging.CreateBitmapSourceFromHBitmap(newBitmap.GetHbitmap(), IntPtr.Zero, Int32Rect.Empty, System.Windows.Media.Imaging.BitmapSizeOptions.FromEmptyOptions());
            return ret; // */
 
        }
 
        public static System.Windows.Media.Imaging.BitmapImage ToBitmapImage(this System.Drawing.Bitmap bitmap) {
            using (var memory = new MemoryStream()) {
                bitmap.Save(memory, System.Drawing.Imaging.ImageFormat.Png);
                memory.Position = 0;
                var bitmapImage = new System.Windows.Media.Imaging.BitmapImage();
                bitmapImage.BeginInit();
                bitmapImage.StreamSource = memory;
                bitmapImage.CacheOption = System.Windows.Media.Imaging.BitmapCacheOption.OnLoad;
                bitmapImage.EndInit();
                return bitmapImage;
            }
        }
Dasn la zone icone, il m'affiche le début d'une phrase, des fois "Sys...", des fois "Ima...".
Est ce que quelqu'un a une idée ?

Merci d'avance.