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 :

Comment faire disparaitre (oppacifier) un graphe


Sujet :

VB.NET

  1. #1
    Membre à l'essai
    Homme Profil pro
    Étudiant
    Inscrit en
    Mars 2016
    Messages
    13
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Haute Garonne (Midi Pyrénées)

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Mars 2016
    Messages : 13
    Points : 11
    Points
    11
    Par défaut Comment faire disparaitre (oppacifier) un graphe
    Bonjour,
    J'aimerais faire disparaitre/apparaitre un Graph et ses légendes en modifiant son opacité à chaque tick de timer, mais je n'ai réussi qu'a opacifier sa couleur ( Et non pas celle du texte et du fond)
    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
     
    Private Sub Timer5_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer5.Tick
            If opa < 256 And opa > 0 Then
     
                For Each series As Series In Graph_Clients_2.Series
                    For Each point As DataPoint In series.Points
                        point.Color = Color.FromArgb(opa, point.Color)
     
                    Next
                Next
     
                opa = opa + degra
                Graph_Clients_2.Visible = True
            Else : degra = -degra
                opa = opa + degra
                Graph_Clients_2.Visible = False
            End If
     
        End Sub
    Si vous avez une idée je suis preneur ! De plus, j'ai réussi à ralentir le timer en augmentant l'intervalle, mais j'aimerais l’accélérer car même avec l'intervalle à 1, on voit toujours les IPS
    Merci d'avance

  2. #2
    Expert confirmé
    Inscrit en
    Avril 2008
    Messages
    2 564
    Détails du profil
    Informations personnelles :
    Âge : 64

    Informations forums :
    Inscription : Avril 2008
    Messages : 2 564
    Points : 4 441
    Points
    4 441
    Par défaut
    bonjour
    Mais comme c'est un chart ou differentes couleurs sont utilisees dans des layers differentes un peu partout c'est difficile....
    La seule astuce possible c'est de prendre un "snap-shot" du control Chart dans un Bitmap au chargement (ou à toute autre instant souhaite ) avec le concour du class Control.DrawToBitmap(bmp, Control.ClientRectangle)...

    Le Bitmap est ensuite affiche dans une 2eme control PicBox..
    Pour la rapidite du traitement il est fait appel aux servicex du class BitmapData pour changer l'opacite du bitmap "snap-shot" et le reaffichage du bitmap sur le picbox....
    Et comme le sosie du mechant captain William(Chart) dans the Invaders ,le PicBox(mis à SendToBack et au meme location que le Chart) ,s'interpose entre nous et le captain William
    Le Timer s'occupe de fader le snap-shot et l'update de Picbox.Image
    Le seul point noir de ton post c'est de ne pas avoir mentionne le contexte d'utilisation: parce que le fading je suppose qu'il ne dure pas ad eternam !!!

    code .vb de :
    1/ class Helper LockBitmap:

    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
    97
     
     
    Imports System.Drawing.Imaging
    Imports System.Runtime.InteropServices.Marshal
     
    Public Class LockBitmap
        Private BaseImage As Bitmap
        Private BaseImageWidth As Integer
        Private BaseImageHeight As Integer
        Private TotalPixels As Integer
        Private ImageAddress As IntPtr
        Private ImageContent As BitmapData
        Private ImageBuffer() As Integer
     
        Public Property Image() As Bitmap
            ' ----- User access to the relevant image.
            Get
                Return BaseImage
            End Get
            Set(ByVal Value As Bitmap)
                Dim canvas As Graphics
                BaseImage = New Bitmap(Value.Width, _
                   Value.Height, Value.PixelFormat)
                canvas = Graphics.FromImage(BaseImage)
                canvas.DrawImage(Value, 0, 0, _
                   Value.Width, Value.Height)
                canvas.Dispose()
            End Set
        End Property
     
        Private Sub LockTheImage()
            ' ----- Lock the image in memory. How much room      do we need?
            BaseImageWidth = BaseImage.Width
            BaseImageHeight = BaseImage.Height
            TotalPixels = BaseImageWidth * BaseImageHeight
     
            ' ----- Create a stable (locked) area in memory. It    will store 32-bit alpha color images.
            ReDim ImageBuffer(TotalPixels - 1)
            ImageContent = BaseImage.LockBits( _
               New Rectangle(0, 0, BaseImageWidth, _
               BaseImageHeight), ImageLockMode.ReadWrite, _
               PixelFormat.Format32bppArgb)
            ImageAddress = ImageContent.Scan0
     
            ' ----- Associate the buffer and the locked memory.
            Copy(ImageAddress, ImageBuffer, 0, TotalPixels)
        End Sub
     
        Private Sub UnlockTheImage()
            ' ----- Unlock the memory area.
            Copy(ImageBuffer, 0, ImageAddress, TotalPixels)
            Image.UnlockBits(ImageContent)
            ImageContent = Nothing
            ReDim ImageBuffer(0)
        End Sub
        Public Sub MakeOpacity(ByVal alpha As Integer)
            ' ----- Make a grayscale version of the image.
            Dim pixelIndex As Integer
            Dim thePixel As Integer
            Dim alphaPart As Integer
            Dim redPart As Integer
            Dim greenPart As Integer
            Dim bluePart As Integer
     
            Dim y As Integer
            Dim x As Integer
     
            ' ----- Lock the image for speed.
            LockTheImage()
     
            ' ----- Process each pixel in the grid.
            For y = 0 To BaseImageHeight - 1
                For x = 0 To BaseImageWidth - 1
                    ' ----- Locate the pixel's color.
                    pixelIndex = y * BaseImageWidth + x
                    thePixel = ImageBuffer(pixelIndex)
     
                    ' ----- Extract the color values.
                    alphaPart = (thePixel >> 24) And &HFF
                    redPart = (thePixel >> 16) And &HFF
                    greenPart = (thePixel >> 8) And &HFF
                    bluePart = thePixel And &HFF
     
                    ' ----- Set opacity.
                    alphaPart = alpha
                    ' ----- Set the pixel.
                    'Retain the original color.
                    ImageBuffer(pixelIndex) = (alphaPart << 24) + _
                       (redPart << 16) + (greenPart << 8) + bluePart
                Next x
            Next y
     
            ' ----- Finished. Unlock the image.
            UnlockTheImage()
        End Sub
     
    End Class
    code du Form utilisateur avec :
    -un chart et un picbox droppe dessus...
    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
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
     
    Imports System.Windows.Forms.DataVisualization
    Imports System.Windows.Forms.DataVisualization.Charting
    Imports System.Drawing.Imaging
    Imports System.Runtime.InteropServices
    Public Class FormGraph
     
        Private alpha As Integer = 255
        Private degra As Integer = 5
        Private flag As Boolean
        Private lock As LockBitmap
        Private bmpSnapShot As Bitmap = Nothing
        Public Sub New()
     
            ' Cet appel est requis par le concepteur.
            InitializeComponent()
     
            ' Ajoutez une initialisation quelconque après l'appel InitializeComponent().
            PictureBox1.SizeMode = PictureBoxSizeMode.AutoSize
            PictureBox1.Location = Chart1.Location
            PictureBox1.SendToBack()
            Chart1.BringToFront()
        End Sub
        Private Sub FormGraph_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
     
            Timer1.Enabled = False
            AddPoints()
            bmpSnapShot = New Bitmap(Chart1.ClientSize.Width, Chart1.ClientSize.Height)
            Using gr As Graphics = Chart1.CreateGraphics
                Chart1.DrawToBitmap(bmpSnapShot, Chart1.ClientRectangle)
                PictureBox1.Image = bmpSnapShot
     
            End Using
     
            lock = New LockBitmap
            lock.Image = PictureBox1.Image
            Timer1.Enabled = True
            Chart1.SendToBack()
            PictureBox1.BringToFront()
     
     
     
     
     
     
     
     
     
        End Sub
        Private rnd As New Random
        Private Sub AddPoints()
            Dim l As New List(Of Point)
            Dim p As Point
            For index = 1 To 100
                p = New Point(rnd.Next(0, 100), rnd.Next(0, 100))
                Chart1.Series(0).Points.AddXY(p.X, p.Y)
                Chart1.Series(0).Color = Color.Red
            Next
     
     
     
        End Sub
     
     
     
     
        Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
     
            alpha += degra
            If alpha > 255 Then
     
                alpha = 255
                degra = -degra
            End If
     
            If alpha < 0 Then
     
                alpha = 0
                degra = -degra
            End If
     
     
            lock.MakeOpacity(alpha)
     
            PictureBox1.Image = lock.Image
     
     
     
     
     
     
     
     
     
        End Sub
     
     
     
     
     
     
     
     
     
     
    End Class
    bon code....

  3. #3
    Membre à l'essai
    Homme Profil pro
    Étudiant
    Inscrit en
    Mars 2016
    Messages
    13
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Haute Garonne (Midi Pyrénées)

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Mars 2016
    Messages : 13
    Points : 11
    Points
    11
    Par défaut
    Merci beaucoup, ça marche parfaitement !

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

Discussions similaires

  1. Réponses: 2
    Dernier message: 21/08/2009, 09h51
  2. Comment faire disparaitre le "context"
    Par nicorama dans le forum Servlets/JSP
    Réponses: 4
    Dernier message: 10/06/2008, 17h41
  3. Réponses: 5
    Dernier message: 31/03/2008, 10h41
  4. comment faire disparaitre automatiquement l'initialisation Activex
    Par ludo_84 dans le forum Macros et VBA Excel
    Réponses: 2
    Dernier message: 21/05/2007, 12h44
  5. Comment faire pour enregister un graphe
    Par morrison29 dans le forum VB 6 et antérieur
    Réponses: 1
    Dernier message: 07/11/2006, 13h58

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