Bonjour,

Je m'arrache les cheveux (pour changer) pour initialiser un bête WriteableBitmap :

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
List<Color> col = new List<Color>();
col.Add(Colors.Black);
col.Add(Colors.White);
BitmapPalette new_pal = new BitmapPalette((IList<Color>) col);
 
WriteableBitmap wb = new WriteableBitmap(20, 20, 96, 96, PixelFormats.Bgra32, null);
try
{
    wb = new WriteableBitmap(20, 20, 96, 96, PixelFormats.Indexed1, new_pal);
}
catch (Exception e)
{
   Console.WriteLine(e.Message);
}
L'initialisation avec le format BGRA marche nickel, mais dès que j'essaie d'initialiser en Indexed, ça bloque :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
InvalidCastException à System.Windows.Media.Imaging.WriteableBitmap..ctor(Int32 pixelWidth, Int32 pixelHeight, Double dpiX, Double dpiY, PixelFormat pixelFormat, BitmapPalette palette)
Merci d'avance pour votre aide !