Bonjour à tous! Voilà je dois dessiner l'histogramme d'une image en fonction d'un choix de l'utilisateur (4 radio boutons, 1 pour chaque composante (RGB) et un pour toutes les composantes en même temps). J'ai réussi à dessiner mon graphique mais je ne parviens pas à accéder à mon tableau d'entiers. Je vous poste mon code:Les 4 slots de mes radio buttons appellent tous AfficherHisto (qui est pour l'instant...vide). Mon problème n'est pas d'initialiser l'histogramme mais de l'afficher. J'ai aussi un paintEvent dans une seconde classe nommée CHisto qui dessine pour l'instant mon graphique (uniquement les axes).
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96 //FenPrincipale.h void AfficheHistogramme(int Coul) ; //Une méthode privée pour l'affichage int* Histo ( int Coul, int &Maxi); //Une méthode publique pour l'initialisation void RedRadio(); //Les slots connectés aux radio boutons respectifs void BlueRadio(); void GreenRadio(); void AllRadio(); //FenPrincipale.cpp Ma fonction int* Histo(int Coul, int& Maxi) int tab[256] = {0}; Maxi = tab[0]; if (Coul == 0) { for (int i = 0; i < Image->width(); i++) { for (int j = 0; j < Image->height(); j++) { for (int k = 0; k < 256; k++) { QColor Pal = Image->pixel(i,j); int moy = (Pal.red()+ Pal.green() + Pal.blue())/3; if (k == moy) { tab[k]++; } if (tab[k] < tab[k+1]) Maxi = tab[k+1]; } } } } if (Coul == 1) { for (int i = 0; i < Image->width(); i++) { for (int j = 0; j < Image->height(); j++) { for (int k = 0; k < 256; k++) { QColor Pal = Image->pixel(i,j); if (k == Pal.red()) { tab[k]++; } if (tab[k] < tab[k+1]) Maxi = tab[k+1]; } } } } if (Coul == 2) { for (int i = 0; i < Image->width(); i++) { for (int j = 0; j < Image->height(); j++) { for (int k = 0; k < 256; k++) { QColor Pal = Image->pixel(i,j); if (k == Pal.green()) { tab[k]++; } if (tab[k] < tab[k+1]) Maxi = tab[k+1]; } } } } if (Coul == 3) { for (int i = 0; i < Image->width(); i++) { for (int j = 0; j < Image->height(); j++) { for (int k = 0; k < 256; k++) { QColor Pal = Image->pixel(i,j); if (k == Pal.blue()) { tab[k]++; } if (tab[k] < tab[k+1]) Maxi = tab[k+1]; } } } } return tab;
Il faudrait que je puisse accéder à mon tableau mais je ne sais pas comment faire et je ne vois pas trop quoi mettre dans ma fonction AfficherHisto.
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 QPainter painter(this); painter.setWindow(-10,-10,255,255); QLineF axe_horiz(0,0,100,100); QLineF axe_verti(0,0,100,100); painter.setFont(QFont("Calibri", 4)); painter.drawText(0,-1,"0"); painter.drawText(-2,148,"255"); painter.save(); painter.rotate(45); painter.drawLine(axe_horiz); painter.restore(); painter.save(); painter.rotate(-45.4); painter.drawLine(axe_verti); painter.restore();
J'ai joins une image de ce à quoi il faut arriver (un widget est inclus dans le QDockWidget que vous pouvez voir et est rpomu en CHisto).
Merci d'avance pour vos réponses!
PS: Je m'excuse d'avance si le code précédent pique les yeux des vétérans programmeurs...![]()
Partager