salut
j'ai besoin de savoir la position de l'image dans une picture box lors du mode Zoom comment peut on calcuer sa???
salut
j'ai besoin de savoir la position de l'image dans une picture box lors du mode Zoom comment peut on calcuer sa???
j'ai trouvé la solution
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 /// <summary> /// donne les paramètres pour la position de l'image ;) /// </summary> /// <param name="pbox">PictureBox qui contient l'image</param> public void OffsetOfImage(PictureBox pbox) { // Calculer les taux d'étirement/compression de l'image float xRatio = 1F; float yRatio = 1F; if (pbox.SizeMode == PictureBoxSizeMode.Zoom) { float a = (float)pbox.Height / (float)pbox.Image.Height; float b = (float)pbox.Width / (float)pbox.Image.Width; xRatio = Math.Min(a, b); yRatio = xRatio; } //// Calculer la taille de l'image affichée Size imgs = new Size((int)(pbox.Image.Width * xRatio), (int)(pbox.Image.Height * yRatio)); //calculer les différances entre l'image et le picturebox int diffx = (int)((pbox.Width - pbox.Image.Width * xRatio) / 2); int diffy = (int)((pbox.Height - pbox.Image.Height * yRatio) / 2); //min est le point minimum le plus haut à gauche de l'image min.X = diffx; min.Y = diffy; //max est le point le plus bax à droite de l'image max.X = (int)(diffx + imgs.Width); max.Y = (int)(diffy + imgs.Height); }![]()
Partager