Bonjour,

je souhaite ouvrir des images et récupérer la partie du buffer qui correspond aux plans RGB

Pour le moment, j'ai:

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
        public BitmapSource LoadBMP(string name)
        {
            Uri uri = new Uri(name);
            BmpBitmapDecoder decoder = new BmpBitmapDecoder(uri, BitmapCreateOptions.PreservePixelFormat, BitmapCacheOption.Default);
            BitmapSource bmpI = decoder.Frames[0];
            try
            {
                if (bmpI.Format == PixelFormats.Bgr24)
                {
                    type = 1;
                    myheight = (int)(bmpI.Height * bmpI.DpiY / 96);
                    mywidth = (int)(bmpI.Width * bmpI.DpiX / 96);
                    stride=(int)(3 * bmpI.Width);
                    pixels = new int[(int)(3 * bmpI.Height * bmpI.Width)];
                    bmpI.CopyPixels(pixels, (int)(3 * bmpI.Width), 0);
                    BitmapSource tbmp;
                    tbmp = BitmapSource.Create(mywidth, myheight, 96, 96, PixelFormats.Bgr24, null, pixels, stride);
                    bmpI=tbmp;
                }
            }
            catch 
            {
                MessageBox.Show("Une erreur est apparue image");
            }
            return bmpI;
Je cherche à adapter le code pour ouvrir tout les formats de Bitmap possibles 32 bits et 24 bits.