IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

VB.NET Discussion :

Probleme position de l'image comme drawLine


Sujet :

VB.NET

  1. #1
    Membre actif
    Homme Profil pro
    Étudiant
    Inscrit en
    Janvier 2018
    Messages
    274
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Nord (Nord Pas de Calais)

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Janvier 2018
    Messages : 274
    Points : 237
    Points
    237
    Par défaut Probleme position de l'image comme drawLine
    Bonjour,

    mon problème , que j'arrive pas avoir le même position de l'image comme Drawline ( voir angle à 90 degrés).

    voir mon gif :
    Nom : Animation.gif
Affichages : 134
Taille : 206,1 Ko

    Mon 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
    Imports System.Drawing.Drawing2D
     
    Public Class Form1
     
     
        Private _Main As Image = My.Resources.Droite1
        Private Sub Form1_Paint(sender As System.Object, e As System.Windows.Forms.PaintEventArgs) Handles MyBase.Paint
            Dim g As Graphics = e.Graphics
            g.SmoothingMode = SmoothingMode.AntiAlias
            Dim rect As New Rectangle(50, 10, 500, 500)
            g.DrawEllipse(New Pen(Brushes.Black, 1), rect)
            DrawAngleImage(g, rect)
        End Sub
     
        Private Sub DrawAngleImage(g As Graphics, r As Rectangle)
            Dim center As New Point(r.Width / 1.7, r.Height / 2)
            Dim radius As Integer = center.X * 0.65
            Using Pen As New Pen(Brushes.Black, 20)
                Pen.StartCap = LineCap.RoundAnchor
                Pen.EndCap = LineCap.Flat
                g.SmoothingMode = SmoothingMode.AntiAlias
                g.DrawLine(Pen, center.X, center.Y, center.X + CInt(Math.Sin(NumericUpDown1.Value * Math.PI / 180) * radius), center.Y - CInt(Math.Cos(NumericUpDown1.Value * Math.PI / 180) * radius))
                g.DrawImage(_Main, New Rectangle(CInt(center.X - CInt(_Main.Width / 3.6)) + CInt(Math.Sin(NumericUpDown1.Value * Math.PI / 180) * radius), CInt(center.Y - CInt(_Main.Height / 2.4)) - CInt(Math.Cos(NumericUpDown1.Value * Math.PI / 180) * radius), _Main.Width, _Main.Height), 0, 0, _Main.Width, _Main.Height, GraphicsUnit.Pixel)
            End Using
        End Sub
     
        Private Sub NumericUpDown1_ValueChanged(sender As System.Object, e As System.EventArgs) Handles NumericUpDown1.ValueChanged
            Me.Refresh()
        End Sub
    End Class
    Pouvez-Vous m'aider à avoir la mème position comme drawline(voir angle à 90 degrés). Merci d'avance

  2. #2
    Expert confirmé
    Avatar de popo
    Homme Profil pro
    Analyste programmeur Delphi / C#
    Inscrit en
    Mars 2005
    Messages
    2 661
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Rhône (Rhône Alpes)

    Informations professionnelles :
    Activité : Analyste programmeur Delphi / C#
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Mars 2005
    Messages : 2 661
    Points : 5 224
    Points
    5 224
    Par défaut
    As-tu regardé du coté de RotateTransform ?

    https://learn.microsoft.com/fr-fr/do...owsdesktop-8.0

  3. #3
    Membre actif
    Homme Profil pro
    Étudiant
    Inscrit en
    Janvier 2018
    Messages
    274
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Nord (Nord Pas de Calais)

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Janvier 2018
    Messages : 274
    Points : 237
    Points
    237
    Par défaut
    Bonsoir popo, merci d'avoir répondu.

    j'ai trouver la solution à mon problème . voici ce que ça donne video gif
    Nom : Animation.gif
Affichages : 100
Taille : 374,3 Ko

  4. #4
    Membre expérimenté
    Profil pro
    Inscrit en
    Septembre 2010
    Messages
    1 105
    Détails du profil
    Informations personnelles :
    Âge : 45
    Localisation : France

    Informations forums :
    Inscription : Septembre 2010
    Messages : 1 105
    Points : 1 607
    Points
    1 607
    Par défaut
    Tu pourrais aussi indiquer comment tu as résolu ton souci (à mon avis la réponse de popo t'a bien aidé)

  5. #5
    Membre actif
    Homme Profil pro
    Étudiant
    Inscrit en
    Janvier 2018
    Messages
    274
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Nord (Nord Pas de Calais)

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Janvier 2018
    Messages : 274
    Points : 237
    Points
    237
    Par défaut
    Bonjour,

    j'ai fait ceci :
    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
    Dim newMain As Bitmap = RotateImage(_Main, NumericUpDown1.Value - 90, New Point(center.X, center.Y))
    g.DrawImage(newMain, CInt(x - newMain.Width / 1.7) + CInt(Math.Sin(NumericUpDown1.Value * Math.PI / 180) * radius), CInt(y - newMain.Height / 2) - CInt(Math.Cos(NumericUpDown1.Value * Math.PI / 180) * radius), newMain.Width, newMain.Height)
     
    Private Function RotateImage(ByVal bmp As Image, ByVal angle As Integer, ByVal center As Point) As Bitmap
            If bmp Is Nothing Then
                Throw New ArgumentNullException("image")
            End If
            Dim alpha As Single = angle
            While alpha < 0
                alpha += 360
            End While
            Dim gamma As Single = 90
            Dim beta As Single = 180 - angle - gamma
            Dim c1 As Single = bmp.Height
            Dim a1 As Single = Math.Abs(CSng((c1 * Math.Sin(alpha * Math.PI / 180))))
            Dim b1 As Single = Math.Abs(CSng((c1 * Math.Sin(beta * Math.PI / 180))))
            Dim c2 As Single = bmp.Width
            Dim a2 As Single = Math.Abs(CSng((c2 * Math.Sin(alpha * Math.PI / 180))))
            Dim b2 As Single = Math.Abs(CSng((c2 * Math.Sin(beta * Math.PI / 180))))
            Dim width As Integer = Convert.ToInt32(b2 + a1)
            Dim height As Integer = Convert.ToInt32(b1 + a2)
            Dim rotatedImage As New Bitmap(width, height)
            Using g As Graphics = Graphics.FromImage(rotatedImage)
                g.TranslateTransform(rotatedImage.Width / 2, rotatedImage.Height / 2)
                g.RotateTransform(angle)
                g.TranslateTransform(-rotatedImage.Width / 2, -rotatedImage.Height / 2)
                g.DrawImage(bmp, New Point((width - bmp.Width) / 2, (height - bmp.Height) / 2))
            End Using
            Return rotatedImage
        End Function
    si vous avez une autre solution plus simple. je prend. cordialement

  6. #6
    Membre expérimenté
    Profil pro
    Inscrit en
    Septembre 2010
    Messages
    1 105
    Détails du profil
    Informations personnelles :
    Âge : 45
    Localisation : France

    Informations forums :
    Inscription : Septembre 2010
    Messages : 1 105
    Points : 1 607
    Points
    1 607
    Par défaut
    Remarque peut-être bête, mais les lignes 24 et 26 sont vraiment utiles ? sauf erreur de ma part, les 2 opérations s'annulent, non ? (quoique)

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. [CR.NET] Probleme d'affichage d'image
    Par ahervieux dans le forum SAP Crystal Reports
    Réponses: 3
    Dernier message: 25/06/2005, 14h06
  2. Probleme d'affichage d'image
    Par nenoeil dans le forum ASP
    Réponses: 2
    Dernier message: 03/06/2005, 11h26
  3. probleme redimensionnement d'une image
    Par meteor4 dans le forum Général JavaScript
    Réponses: 6
    Dernier message: 29/11/2004, 13h58
  4. Mkisofs - problème pour créer une image
    Par tomnie dans le forum Applications et environnements graphiques
    Réponses: 4
    Dernier message: 04/08/2004, 11h44
  5. [TP][MULTI-PROBLEME]Comment afficher des images pcx
    Par mikoeur dans le forum Turbo Pascal
    Réponses: 7
    Dernier message: 24/10/2002, 13h57

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo