OVH Cloud OVH Cloud

transparence

4 réponses
Avatar
Pyroa
Bonsoir ( ou bonjour je sais plus ou j'en suis ),

Je dessin grace à un objet graphics des texture directement sur ma form
principale, e par dessus j'aimerais dessiner un gif animé avec de la
transparence.
Pour ce faire j'ai utilisé un picturebox dans lequel je charge mon gif
animé, mais pas de transparence !
et si je le dessine avec un objet graphics je pense que cela ne sera pas
animé ( j'ai pas essayé la derniere solution )
donc j'aimerais savoir si j'ai ommis quelquechose ?

merci d'avance !
@+

4 réponses

Avatar
David Bouchard
Dans ton picturebox, a tu essayé de mettre la propriété backcolor à
transparent

David

"Pyroa" <##> a écrit dans le message de news:
%
Bonsoir ( ou bonjour je sais plus ou j'en suis ),

Je dessin grace à un objet graphics des texture directement sur ma form
principale, e par dessus j'aimerais dessiner un gif animé avec de la
transparence.
Pour ce faire j'ai utilisé un picturebox dans lequel je charge mon gif
animé, mais pas de transparence !
et si je le dessine avec un objet graphics je pense que cela ne sera pas
animé ( j'ai pas essayé la derniere solution )
donc j'aimerais savoir si j'ai ommis quelquechose ?

merci d'avance !
@+



Avatar
Pyroa
J'ai essayé après avoir envoyé le post, mais il faut mettre le transparency
key à color.transparent ...
Ca marche, mais je trouve tout ca tres peu pratique. En plus lorsque je fait
ca , les dessins des boutons
pour controler la fenetre on le blanc qui deviens transparent ...
avec GDI+ cela aurais été plus simple mais je ne sait pas dessiner un gif
animé et je ne sais meme pas si on peux le faire ..

merci quand meme !

"David Bouchard" a écrit dans le message de news:

Dans ton picturebox, a tu essayé de mettre la propriété backcolor à
transparent

David

"Pyroa" <##> a écrit dans le message de
news: %
Bonsoir ( ou bonjour je sais plus ou j'en suis ),

Je dessin grace à un objet graphics des texture directement sur ma form
principale, e par dessus j'aimerais dessiner un gif animé avec de la
transparence.
Pour ce faire j'ai utilisé un picturebox dans lequel je charge mon gif
animé, mais pas de transparence !
et si je le dessine avec un objet graphics je pense que cela ne sera pas
animé ( j'ai pas essayé la derniere solution )
donc j'aimerais savoir si j'ai ommis quelquechose ?

merci d'avance !
@+







Avatar
David Bouchard
Voici deux section de code que tu pourrais trouvé très intéressante sur les
gifs animés, ceci fonctionne très bien.

Crée toi deux formulaires et remplace le contenu de chacun par une des
sections de code. La première te permet de comprendre comment dessiner un
gif animé et la seconde comment choisir le frame du gif que tu désire
dessiner.

David

Public Class Form1

Inherits System.Windows.Forms.Form

#Region " Code généré par le Concepteur Windows Form "

Public Sub New()

MyBase.New()

'Cet appel est requis par le Concepteur Windows Form.

InitializeComponent()

MyInitializeComponent()

'Ajoutez une initialisation quelconque après l'appel InitializeComponent()

End Sub

'La méthode substituée Dispose du formulaire pour nettoyer la liste des
composants.

Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)

If disposing Then

If Not (components Is Nothing) Then

components.Dispose()

End If

End If

MyBase.Dispose(disposing)

End Sub

'Requis par le Concepteur Windows Form

Private components As System.ComponentModel.IContainer

'REMARQUE : la procédure suivante est requise par le Concepteur Windows Form

'Elle peut être modifiée en utilisant le Concepteur Windows Form.

'Ne la modifiez pas en utilisant l'éditeur de code.

Friend WithEvents Button1 As System.Windows.Forms.Button

Friend WithEvents PictureBox1 As System.Windows.Forms.PictureBox

<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()

Me.Button1 = New System.Windows.Forms.Button

Me.PictureBox1 = New System.Windows.Forms.PictureBox

Me.SuspendLayout()

'

'Button1

'

Me.Button1.Location = New System.Drawing.Point(16, 8)

Me.Button1.Name = "Button1"

Me.Button1.TabIndex = 0

Me.Button1.Text = "Button1"

'

'PictureBox1

'

Me.PictureBox1.Location = New System.Drawing.Point(24, 80)

Me.PictureBox1.Name = "PictureBox1"

Me.PictureBox1.Size = New System.Drawing.Size(192, 160)

Me.PictureBox1.TabIndex = 1

Me.PictureBox1.TabStop = False

'

'Form1

'

Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)

Me.ClientSize = New System.Drawing.Size(400, 266)

Me.Controls.Add(Me.PictureBox1)

Me.Controls.Add(Me.Button1)

Me.Name = "Form1"

Me.Text = "Form1"

Me.ResumeLayout(False)

End Sub

#End Region



Private _bAnimated As Boolean

Private _Bitmap As Bitmap

Private Sub MyInitializeComponent()

_Bitmap = New Bitmap("C:feu_camp3.gif")

ToogleAnimation()

End Sub

Private Sub ToogleAnimation()

If Not ImageAnimator.CanAnimate(_Bitmap) Then Exit Sub

If _bAnimated Then

ImageAnimator.StopAnimate(_Bitmap, New EventHandler(AddressOf
Me.OnFrameChanged))

Else

ImageAnimator.Animate(_Bitmap, New EventHandler(AddressOf
Me.OnFrameChanged))

End If

_bAnimated = Not _bAnimated

End Sub

Private Sub OnFrameChanged(ByVal sender As Object, ByVal e As EventArgs)

Me.PictureBox1.Invalidate()

End Sub

Private Sub picAff_Paint(ByVal sender As Object, ByVal e As
System.Windows.Forms.PaintEventArgs) Handles PictureBox1.Paint

ImageAnimator.UpdateFrames()

e.Graphics.DrawImage(_Bitmap, New Point(0, 0))

End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click

If _bAnimated Then

Me.Button1.Text = "&Start"

Else

Me.Button1.Text = "&Stop"

End If

ToogleAnimation()

End Sub

End Class









Public Class Form2

Inherits System.Windows.Forms.Form

#Region " Code généré par le Concepteur Windows Form "

Public Sub New()

MyBase.New()

'Cet appel est requis par le Concepteur Windows Form.

InitializeComponent()

'Ajoutez une initialisation quelconque après l'appel InitializeComponent()

End Sub

'La méthode substituée Dispose du formulaire pour nettoyer la liste des
composants.

Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)

If disposing Then

If Not (components Is Nothing) Then

components.Dispose()

End If

End If

MyBase.Dispose(disposing)

End Sub

'Requis par le Concepteur Windows Form

Private components As System.ComponentModel.IContainer

'REMARQUE : la procédure suivante est requise par le Concepteur Windows Form

'Elle peut être modifiée en utilisant le Concepteur Windows Form.

'Ne la modifiez pas en utilisant l'éditeur de code.

Friend WithEvents VScrollBar1 As System.Windows.Forms.VScrollBar

Friend WithEvents PictureBox1 As System.Windows.Forms.PictureBox

<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()

Me.VScrollBar1 = New System.Windows.Forms.VScrollBar

Me.PictureBox1 = New System.Windows.Forms.PictureBox

Me.SuspendLayout()

'

'VScrollBar1

'

Me.VScrollBar1.LargeChange = 1

Me.VScrollBar1.Location = New System.Drawing.Point(256, 32)

Me.VScrollBar1.Name = "VScrollBar1"

Me.VScrollBar1.Size = New System.Drawing.Size(17, 208)

Me.VScrollBar1.TabIndex = 3

'

'PictureBox1

'

Me.PictureBox1.Location = New System.Drawing.Point(16, 40)

Me.PictureBox1.Name = "PictureBox1"

Me.PictureBox1.Size = New System.Drawing.Size(224, 200)

Me.PictureBox1.TabIndex = 4

Me.PictureBox1.TabStop = False

'

'Form2

'

Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)

Me.ClientSize = New System.Drawing.Size(292, 266)

Me.Controls.Add(Me.PictureBox1)

Me.Controls.Add(Me.VScrollBar1)

Me.Name = "Form2"

Me.Text = "Form2"

Me.ResumeLayout(False)

End Sub

#End Region

Private oB As New Bitmap("C:feu_camp3.gif")

Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs)
Handles MyBase.Load

Dim oFD As New
System.Drawing.Imaging.FrameDimension(oB.FrameDimensionsList(0))

Me.VScrollBar1.Maximum = oB.GetFrameCount(oFD) - 1

End Sub



Private Sub pic2_Paint(ByVal sender As System.Object, ByVal e As
System.Windows.Forms.PaintEventArgs) Handles PictureBox1.Paint

Dim oFD As New
System.Drawing.Imaging.FrameDimension(oB.FrameDimensionsList(0))

oB.SelectActiveFrame(oFD, Me.VScrollBar1.Value)

e.Graphics.DrawImage(oB, 0, 0)

End Sub

Private Sub VScrollBar1_Scroll(ByVal sender As System.Object, ByVal e As
System.Windows.Forms.ScrollEventArgs) Handles VScrollBar1.Scroll

Me.PictureBox1.Invalidate()

End Sub

End Class
Avatar
Pyroa
Salut,
Merci pour les codes !
Je connais ces codes ils viennent de C2i.fr ;)
Je pensait qu'il y avait d'autre manière de dessiner un gif sans avoir à
dessiner chaqu'une des frames ....
genre DrawGif("c:mongif.gif").
Bon tans pis ! Merci encore !
@+

"David Bouchard" a écrit dans le message de news:

Voici deux section de code que tu pourrais trouvé très intéressante sur
les gifs animés, ceci fonctionne très bien.

Crée toi deux formulaires et remplace le contenu de chacun par une des
sections de code. La première te permet de comprendre comment dessiner un
gif animé et la seconde comment choisir le frame du gif que tu désire
dessiner.

David

Public Class Form1

Inherits System.Windows.Forms.Form

#Region " Code généré par le Concepteur Windows Form "

Public Sub New()

MyBase.New()

'Cet appel est requis par le Concepteur Windows Form.

InitializeComponent()

MyInitializeComponent()

'Ajoutez une initialisation quelconque après l'appel InitializeComponent()

End Sub

'La méthode substituée Dispose du formulaire pour nettoyer la liste des
composants.

Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)

If disposing Then

If Not (components Is Nothing) Then

components.Dispose()

End If

End If

MyBase.Dispose(disposing)

End Sub

'Requis par le Concepteur Windows Form

Private components As System.ComponentModel.IContainer

'REMARQUE : la procédure suivante est requise par le Concepteur Windows
Form

'Elle peut être modifiée en utilisant le Concepteur Windows Form.

'Ne la modifiez pas en utilisant l'éditeur de code.

Friend WithEvents Button1 As System.Windows.Forms.Button

Friend WithEvents PictureBox1 As System.Windows.Forms.PictureBox

<System.Diagnostics.DebuggerStepThrough()> Private Sub
InitializeComponent()

Me.Button1 = New System.Windows.Forms.Button

Me.PictureBox1 = New System.Windows.Forms.PictureBox

Me.SuspendLayout()

'

'Button1

'

Me.Button1.Location = New System.Drawing.Point(16, 8)

Me.Button1.Name = "Button1"

Me.Button1.TabIndex = 0

Me.Button1.Text = "Button1"

'

'PictureBox1

'

Me.PictureBox1.Location = New System.Drawing.Point(24, 80)

Me.PictureBox1.Name = "PictureBox1"

Me.PictureBox1.Size = New System.Drawing.Size(192, 160)

Me.PictureBox1.TabIndex = 1

Me.PictureBox1.TabStop = False

'

'Form1

'

Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)

Me.ClientSize = New System.Drawing.Size(400, 266)

Me.Controls.Add(Me.PictureBox1)

Me.Controls.Add(Me.Button1)

Me.Name = "Form1"

Me.Text = "Form1"

Me.ResumeLayout(False)

End Sub

#End Region



Private _bAnimated As Boolean

Private _Bitmap As Bitmap

Private Sub MyInitializeComponent()

_Bitmap = New Bitmap("C:feu_camp3.gif")

ToogleAnimation()

End Sub

Private Sub ToogleAnimation()

If Not ImageAnimator.CanAnimate(_Bitmap) Then Exit Sub

If _bAnimated Then

ImageAnimator.StopAnimate(_Bitmap, New EventHandler(AddressOf
Me.OnFrameChanged))

Else

ImageAnimator.Animate(_Bitmap, New EventHandler(AddressOf
Me.OnFrameChanged))

End If

_bAnimated = Not _bAnimated

End Sub

Private Sub OnFrameChanged(ByVal sender As Object, ByVal e As EventArgs)

Me.PictureBox1.Invalidate()

End Sub

Private Sub picAff_Paint(ByVal sender As Object, ByVal e As
System.Windows.Forms.PaintEventArgs) Handles PictureBox1.Paint

ImageAnimator.UpdateFrames()

e.Graphics.DrawImage(_Bitmap, New Point(0, 0))

End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click

If _bAnimated Then

Me.Button1.Text = "&Start"

Else

Me.Button1.Text = "&Stop"

End If

ToogleAnimation()

End Sub

End Class









Public Class Form2

Inherits System.Windows.Forms.Form

#Region " Code généré par le Concepteur Windows Form "

Public Sub New()

MyBase.New()

'Cet appel est requis par le Concepteur Windows Form.

InitializeComponent()

'Ajoutez une initialisation quelconque après l'appel InitializeComponent()

End Sub

'La méthode substituée Dispose du formulaire pour nettoyer la liste des
composants.

Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)

If disposing Then

If Not (components Is Nothing) Then

components.Dispose()

End If

End If

MyBase.Dispose(disposing)

End Sub

'Requis par le Concepteur Windows Form

Private components As System.ComponentModel.IContainer

'REMARQUE : la procédure suivante est requise par le Concepteur Windows
Form

'Elle peut être modifiée en utilisant le Concepteur Windows Form.

'Ne la modifiez pas en utilisant l'éditeur de code.

Friend WithEvents VScrollBar1 As System.Windows.Forms.VScrollBar

Friend WithEvents PictureBox1 As System.Windows.Forms.PictureBox

<System.Diagnostics.DebuggerStepThrough()> Private Sub
InitializeComponent()

Me.VScrollBar1 = New System.Windows.Forms.VScrollBar

Me.PictureBox1 = New System.Windows.Forms.PictureBox

Me.SuspendLayout()

'

'VScrollBar1

'

Me.VScrollBar1.LargeChange = 1

Me.VScrollBar1.Location = New System.Drawing.Point(256, 32)

Me.VScrollBar1.Name = "VScrollBar1"

Me.VScrollBar1.Size = New System.Drawing.Size(17, 208)

Me.VScrollBar1.TabIndex = 3

'

'PictureBox1

'

Me.PictureBox1.Location = New System.Drawing.Point(16, 40)

Me.PictureBox1.Name = "PictureBox1"

Me.PictureBox1.Size = New System.Drawing.Size(224, 200)

Me.PictureBox1.TabIndex = 4

Me.PictureBox1.TabStop = False

'

'Form2

'

Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)

Me.ClientSize = New System.Drawing.Size(292, 266)

Me.Controls.Add(Me.PictureBox1)

Me.Controls.Add(Me.VScrollBar1)

Me.Name = "Form2"

Me.Text = "Form2"

Me.ResumeLayout(False)

End Sub

#End Region

Private oB As New Bitmap("C:feu_camp3.gif")

Private Sub Form1_Load(ByVal sender As Object, ByVal e As
System.EventArgs) Handles MyBase.Load

Dim oFD As New
System.Drawing.Imaging.FrameDimension(oB.FrameDimensionsList(0))

Me.VScrollBar1.Maximum = oB.GetFrameCount(oFD) - 1

End Sub



Private Sub pic2_Paint(ByVal sender As System.Object, ByVal e As
System.Windows.Forms.PaintEventArgs) Handles PictureBox1.Paint

Dim oFD As New
System.Drawing.Imaging.FrameDimension(oB.FrameDimensionsList(0))

oB.SelectActiveFrame(oFD, Me.VScrollBar1.Value)

e.Graphics.DrawImage(oB, 0, 0)

End Sub

Private Sub VScrollBar1_Scroll(ByVal sender As System.Object, ByVal e As
System.Windows.Forms.ScrollEventArgs) Handles VScrollBar1.Scroll

Me.PictureBox1.Invalidate()

End Sub

End Class