Zoom sur coordonnées de la souris dans picutre box

Résolu
podolis Messages postés 71 Date d'inscription mardi 18 mars 2008 Statut Membre Dernière intervention 19 décembre 2010 - 11 avril 2008 à 11:35
cs_antho2005 Messages postés 150 Date d'inscription samedi 8 avril 2006 Statut Membre Dernière intervention 1 mai 2012 - 13 avril 2008 à 12:58
Je cherche à faire un zoom  sur les coordonnées de ma souris (après un clique sur la picutrebox), pour le moment j'utilise ce code qui me permet juste de centré mon image mais pas de zoomé sur mes coordonnées
Rq : Ma pictureBox sur situe dans un panel
 Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        'Zoom      
        PictureBox1.Width = PictureBox1.Width * 1.2
        PictureBox1.Height = PictureBox1.Height * 1.2
        'Repositionnement de l'image par rapport au panel      
        PictureBox1.Left = (Panel1.Width - PictureBox1.Width) / 2
        PictureBox1.Top = (Panel1.Height - PictureBox1.Height) / 2
    End Sub

 Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        PictureBox1.Width = PictureBox1.Width / 1.2
        PictureBox1.Height = PictureBox1.Height / 1.2
        PictureBox1.Left = (Panel1.Width - PictureBox1.Width) / 2
        PictureBox1.Top = (Panel1.Height - PictureBox1.Height) / 2
    End Sub

Ma souris me renvoi ces coordonnées sous deux variables x1 et y1
J'ai faguement l'impression qu'il s'agit plus d'un problème de maths que de programmation
Médéric
Ergonome Logiel
(VB.NET-Débutant)

6 réponses

cs_antho2005 Messages postés 150 Date d'inscription samedi 8 avril 2006 Statut Membre Dernière intervention 1 mai 2012 3
12 avril 2008 à 11:17
De rien et désolé pour les espaces ... apparemment le forum a des petits problèmes quand c'est en bleu ou je sais pas trop pourquoi
par contre je pense que c'est plutôt
PositionDepart.X = LImage.Width / 2 - Coordonees.X * 2
PositionDepart.Y = LImage.Height / 2 - Coordonees.Y * 2
au lieu de

PositionDepart.X = LImage.Width / Facteur - Coordonees.X * Facteur
PositionDepart.Y = LImage.Height / Facteur - Coordonees.Y * Facteur
C'était un test que j'avais fait ...
En fait je sais pas trop

Antho25
3
cs_antho2005 Messages postés 150 Date d'inscription samedi 8 avril 2006 Statut Membre Dernière intervention 1 mai 2012 3
11 avril 2008 à 18:18
Bon, voilà sauf que ça descent un peu au bout de quelques zoom:

   Dim ZoomActu
As
Double = 1

   Dim factor
As
Double = 1.2

   Dim LeDepart
As
New Point(0, 0)
   
Private
Function ZoomerImage(
ByVal LaPictureBox
As PictureBox,
ByVal Coordonees
As Point,
ByVal Facteur
As
Double)
As Point

      Dim LImage
As Image = LaPictureBox.Image

      Dim NewImage
As Graphics = LaPictureBox.CreateGraphics

      Dim NouvelleTaille
As Size

      Dim EcartTaille
As Size

      Dim PositionDepart
As Point
      NewImage.Clear(LaPictureBox.BackColor)
      NouvelleTaille.Width = LImage.Width * Facteur
      NouvelleTaille.Height = LImage.Height * Facteur
      EcartTaille.Width = NouvelleTaille.Width - LImage.Width
      EcartTaille.Height = NouvelleTaille.Height - LImage.Height

      If Facteur < 1
Then
         PositionDepart.X = EcartTaille.Width / 2 * -1
         PositionDepart.Y = EcartTaille.Height / 2 * -1

      Else
         PositionDepart.X = LImage.Width / Facteur - Coordonees.X * Facteur
         PositionDepart.Y = LImage.Height / Facteur - Coordonees.Y * Facteur

         If PositionDepart.X > 0
Then PositionDepart.X = 0

         If PositionDepart.Y > 0
Then PositionDepart.Y = 0

      End
If
      NewImage.DrawImage(LImage, PositionDepart.X, PositionDepart.Y, NouvelleTaille.Width, NouvelleTaille.Height)

      Return PositionDepart
   
End
Function
   Private
Sub PicConteneuse_MouseUp(
ByVal sender
As
Object,
ByVal e
As System.Windows.Forms.MouseEventArgs)
Handles
      PicConteneuse.MouseUp

      If Zoomer.Checked
Then
         ZoomActu *= factor

      Else
         ZoomActu /= factor

      End
If
      LeDepart = ZoomerImage(PicConteneuse,
New Point(e.Location.X - LeDepart.X, e.Location.Y - LeDepart.Y), ZoomActu)

   End
Sub
   Private
Sub TailleDorigine_Click(
ByVal sender
As System.Object,
ByVal e
As System.EventArgs)
Handles TailleDorigine.Click
         ZoomActu = 1
         LeDepart = ZoomerImage(PicConteneuse,
New Point(0, 0), 1)

   End
Sub

Après, je te laisse te débrouiller pour améliorer ça

Antho25
1
podolis Messages postés 71 Date d'inscription mardi 18 mars 2008 Statut Membre Dernière intervention 19 décembre 2010 1
11 avril 2008 à 18:31
Merci

Médéric
Ergonome Logiel
(VB.NET-Débutant)
1
cs_antho2005 Messages postés 150 Date d'inscription samedi 8 avril 2006 Statut Membre Dernière intervention 1 mai 2012 3
13 avril 2008 à 12:58
Et j'ai oublié un petit truc:

If PositionDepart.X + NouvelleTaille.Width < LaPictureBox.Width Then PositionDepart.X = LaPictureBox.Width - NouvelleTaille.Width
If PositionDepart.Y + NouvelleTaille.Height < LaPictureBox.Height Then PositionDepart.Y = LaPictureBox.Height - NouvelleTaille.Height

juste après:

If PositionDepart.X > 0 Then PositionDepart.X = 0
If PositionDepart.Y > 0 Then PositionDepart.Y = 0

Voilà, c'est tout
1

Vous n’avez pas trouvé la réponse que vous recherchez ?

Posez votre question
cs_antho2005 Messages postés 150 Date d'inscription samedi 8 avril 2006 Statut Membre Dernière intervention 1 mai 2012 3
11 avril 2008 à 14:47
Salut,
Si tu veux juste adapter l'image à la taille de la PictureBox, il suffit de faire comme tu fait et de mettre la propriété SizeMode à Stretch.

Si par contre tu veux que l'image soit zoomée dans son conteneur, je suis en train de te faire un code, je te le poste dès que j'ai fini ...

Antho25
0
podolis Messages postés 71 Date d'inscription mardi 18 mars 2008 Statut Membre Dernière intervention 19 décembre 2010 1
11 avril 2008 à 15:28
Merci à toi antho2005

Médéric
Ergonome Logiel
(VB.NET-Débutant)
0
Rejoignez-nous