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
| 'Création d'un Graphics pour travailler sur l'image "Peinture"
Dim PeintureGraphics As Graphics = Graphics.FromImage(Peinture)
'Ouverture de l'image désiré à mélanger
Dim PNG As Bitmap = Image.FromFile("C:\losange transparent.png")
'Création d'une Bitmap à la taille du contrôle
Dim PNGRetail As Bitmap = New Bitmap(Me.Width,Me.Height)
'Création d'un mappage Transparent -> Magenta!
Dim map(0) As System.Drawing.Imaging.ColorMap
map(0) = New System.Drawing.Imaging.ColorMap()
map(0).OldColor = Color.FromArgb(0,0,0,0)
map(0).NewColor = Color.Magenta
'Création d'attributs d'image, avec le mappage créer juste avant comme contenu
Dim myAttributs As New ImageAttributes()
myAttributs.SetRemapTable(map)
'Je créé un Graphics pour travailler sur la Bitmap PNGRetail
Dim PNGraphics As Graphics = Graphics.FromImage(PNGRetail)
'Ce rectangle me servira apres pour dire à quel endroit placer l'image dans l'image "Peinture"
Dim Rect As New Rectangle(0,0,Me.Width,Me.Height)
'Je redimensionne l'image PNG à la taille de la PNGRetail
PNGraphics.DrawImage(PNG,0,0,Me.width,Me.Height)
'Je postionne l'image "PNGRetail" dans l'image "Peinture", en changeant sa couleur transparente en Magenta, et en la positionnant à l'emplacement décrit par "Rect"
PeintureGraphics.DrawImage(PNGRetail,Rect,0,0,Me.Width,Me.Height,GraphicsUnit.Pixel,myAttributs)
'Enregistrer la nouvelle image ;)
Peinture.Save("c:\peinture.png") |
Partager