Bonjour,

Comment faire pour déclarer un tableau dynamique à deux dimensions.

J'utilise ce code

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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
 
#include <iostream>
#include <CImg.h>
 
using namespace cimg_library;
using namespace std;
int ColorToID(int);
 
int main(int argc,char *argv[])
{
    const char *MapID = "D:\\MapID.bmp";
    const char *MapBorder = "D:\\MapBorder.bmp";
    const char *MapShading = "D:\\MapShading.bmp";
    CImg<unsigned char> imaID(MapID),imaBorder(MapBorder),imaShading(MapShading);
    const int Width=imaID.dimx();
    const int Height=imaID.dimy();
    int (*ID)=new int[Width][Height];
    for (int i=0; i<Width; i=i+1)
    {
    unsigned char valR;
    unsigned char valG;
    unsigned char valB;
        for (int j=0; j<Height; j=j+1)
            {
                valR = imaID(i,j,0);  // Read the red component at coordinates (i,j).
                valG = imaID(i,j,1);  // Read the green component at coordinates (i,j)
                valB = imaID(i,j,2);  // Read the blue component at coordinates (i,j)
                *ID[i][j]=ColorToID(valR*65536+valG*256+valB);
            }
    }
    /*
    const int NbBlockX=imaID.dimx()/32;
    const int NbBlockY=imaID.dimy()/32;
    for (int i=0; i<NbBlockX; i=i+1)
    {
        for (int j=0; j<NbBlockY; j=j+1)
        {
            int level=5;
 
 
        }
    }
 
    cout << id << endl;*/
    return 0;
}
 
int ColorToID (int rgb)
{
    //color to ID
    // Compact distributed bits
    int i = ((rgb & 0xF00000) >> 12) | ((rgb & 0xF000) >> 8) | ((rgb & 0xF0) >> 4);
 
    // And move them to their correct places.
    return (((i & 0x8)>>1) | ((i & 0x4)<<3) | ((i & 0x2)<<7) | ((i & 0x1)<<11) |
        ((i & 0x80)>>6) | ((i & 0x40)>>2) | ((i & 0x20)<<2) | ((i & 0x10)<<6) |
        ((i& 0x800)>>11) | ((i & 0x400)>>7) | ((i & 0x200)>>3) | ((i & 0x100)<<1));
 
    //ID to color
    // Move bits around
    /*int result = (((id & 0x200)>>1) | ((id & 0x40)<<3) | ((id & 0x8)<<7) | ((id & 0x1)<<11) |
        ((id & 0x400)>>6) | ((id & 0x80)>>2) | ((id & 0x10)<<2) | ((id & 0x2)<<6) |
        ((id & 0x800)>>11) | ((id & 0x100)>>7) | ((id & 0x20)>>3) | ((id & 0x4)<<1));
 
    // Distribute over R, G and B.
    result = ((result & 0xF00) << 12) | ((result & 0xF0) << 8) | ((result & 0xF) << 4);*/
}
La compilation bloque sur la ligne
Code : Sélectionner tout - Visualiser dans une fenêtre à part
int (*ID)=new int[Width][Height];
car Height doit être constant.

Comment faire ?

J'ai cru comprendre qu'il fallait déclarer un tableau de pointeurs à une dimension puis pour chaque valeur un tableau de pointeurs.

J'avoue que je suis encore un peu perdu dans les pointeurs.

Existe-t'il des librairies qui permettent d'utiliser des tableaux dynamiques de façon plus intuitive ?