Problème d'image couleur-N&B
Bonjour
J'affiche une image couleur en cliquant les vignettes d'un form
Code:
1 2 3 4 5 6
| Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
img3 = Me.BackgroundImage
Me.AutoSize = True
Me.ResizeRedraw = True
Me.BackgroundImageLayout = ImageLayout.None
End Sub |
a l'aide d'un menu contextuel je mets cette image en N&B
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
| Public Function GrayScale(ByVal Img As System.Drawing.Image) As System.Drawing.Image
Dim GrayAttributes As System.Drawing.Imaging.ImageAttributes
Dim GrayMatrix As New System.Drawing.Imaging.ColorMatrix
GrayMatrix.Matrix00 = 1 / 3.0F
GrayMatrix.Matrix01 = 1 / 3.0F
GrayMatrix.Matrix02 = 1 / 3.0F
GrayMatrix.Matrix10 = 1 / 3.0F
GrayMatrix.Matrix11 = 1 / 3.0F
GrayMatrix.Matrix12 = 1 / 3.0F
GrayMatrix.Matrix20 = 1 / 3.0F
GrayMatrix.Matrix21 = 1 / 3.0F
GrayMatrix.Matrix22 = 1 / 3.0F
GrayAttributes = New System.Drawing.Imaging.ImageAttributes()
GrayAttributes.SetColorMatrix(GrayMatrix, System.Drawing.Imaging.ColorMatrixFlag.Default, System.Drawing.Imaging.ColorAdjustType.Default)
Dim FinalImg As New System.Drawing.Bitmap(Img.Width, Img.Height)
Dim Graphics As System.Drawing.Graphics = System.Drawing.Graphics.FromImage(FinalImg)
Graphics.DrawImage(Img, New Rectangle(0, 0, FinalImg.Width, FinalImg.Height), 0, 0, FinalImg.Width, FinalImg.Height, System.Drawing.GraphicsUnit.Pixel, GrayAttributes)
Return FinalImg
End Function |
Code:
1 2 3 4 5 6 7
| Private Sub NoirEtBlancToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles NoirEtBlancToolStripMenuItem.Click
Dim img2 As Image
img2 = Me.BackgroundImage
Me.BackgroundImage = GrayScale(img2)
Me.Refresh()
img2.Dispose()
End Sub |
Ensuite je voudrai revenir à l'image en couleur avec ce code
Code:
1 2 3 4 5 6 7 8
| Private Sub CouleurToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CouleurToolStripMenuItem.Click
Me.BackgroundImage = Nothing
Me.AutoSize = True
Me.ResizeRedraw = True
Me.BackgroundImageLayout = ImageLayout.None
Me.BackgroundImage = img3
Me.Refresh()
End Sub |
Mais c'est là qu'est le problème, l'image ne s'affiche pas et j'ai à la place une grande croix rouge
Pouvez-vous m'aider
Merci d'avance