mais il utilise un Form rendu transparent via la propriété TransparencyKeyTu n'es pas obligé de le faire, j'ai utilisé ce moyen pour te montrer que tout peut être transparent.
tu dessines des formes à la main
mais reste le problème de réduction de l'image
Option Strict On Public Class Form1 Dim b As Bitmap Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load b = New Bitmap("image.jpg") b.MakeTransparent(Color.White) End Sub Private Sub Form1_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles Me.Paint e.Graphics.DrawImage(CType(b, Image), New Rectangle(0, 0, 80, 65), New Rectangle(0, 0, b.Width, b.Height), GraphicsUnit.Pixel) End Sub End Class
Public Function Transparent(ByVal MonImage As Image) As System.Drawing.Drawing2D.GraphicsPath 'Transparence réelle Dim X As Integer Dim Y As Integer Dim MaBitmap As New Bitmap(MonImage) 'crée un bitmap à partir de l'image Dim MonGraphicsPath As New System.Drawing.Drawing2D.GraphicsPath() Dim Masque As Color = Color.FromArgb(0) 'MaBitmap.GetPixel(0, 0) 'obtient le pixel au point 0,0 'Parcours de tous les pixels de l'image For X = 0 To MaBitmap.Width - 1 For Y = 0 To MaBitmap.Height - 1 If Not MaBitmap.GetPixel(X, Y).Equals(Masque) Then 'si la couleur du pixel donné n'est pas égale à celle du pixel par défaut, transparent MonGraphicsPath.AddRectangle(New Rectangle(X, Y, 1, 1)) 'on ajoute un rectangle à notre forme (graphicspath) End If Next Next 'Libère le bitmap et retourne la nouvelle forme graphique MaBitmap.Dispose() Return MonGraphicsPath End Function
Boule.Region = New system.Drawing.Region(Transparent(Boule.BackgroundImage))
Vous n’avez pas trouvé la réponse que vous recherchez ?
Posez votre questionOption Strict On Public Class Form1 Dim b1 As New Bitmap(30, 30) Dim b2 As New Bitmap(30, 30) Dim g1 As Graphics = Graphics.FromImage(b1) Dim g2 As Graphics = Graphics.FromImage(b2) Dim rect As New Rectangle(0, 0, 30, 30) Dim x1, y1, x2, y2 As Integer Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load g1.FillRectangle(Brushes.White, rect) g2.FillRectangle(Brushes.White, rect) g1.FillEllipse(Brushes.Blue, rect) g2.FillEllipse(Brushes.Red, rect) b1.MakeTransparent(Color.White) b2.MakeTransparent(Color.White) With Me .Size = New Size(400, 400) .FormBorderStyle = FormBorderStyle.None .BackColor = Color.White .TransparencyKey = Color.White x2 = .Width y2 = .Height End With Dim tmr As New System.Timers.Timer(15) AddHandler tmr.Elapsed, AddressOf tmr_Elapsed tmr.Start() End Sub Private Sub Form1_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles Me.Paint e.Graphics.DrawRectangle(New Pen(Brushes.Black, 10), Me.ClientRectangle) e.Graphics.DrawString("J", New Font("Wingdings", 40), Brushes.YellowGreen, New Point(170, 170)) e.Graphics.DrawImage(b1, New Point(x1, y1)) e.Graphics.DrawImage(b2, New Point(x2, y2)) End Sub Private Sub tmr_Elapsed(ByVal sender As Object, ByVal e As Timers.ElapsedEventArgs) Me.Invalidate(New Rectangle(x1, y1, 32, 32)) Me.Invalidate(New Rectangle(x2, y2, 32, 32)) x1 += 1 : y1 += 1 : x2 -= 1 : y2 -= 1 If x1 > Me.Width Then DirectCast(sender, Timers.Timer).Stop() End Sub End Class
Public Function SubCallback() As Boolean Return True End Function Sub RéduireImage() Dim CallBack As New Image.GetThumbnailImageAbort(AddressOf SubCallback) ObjetImage = Objet.Image 'Il faut déclarer ObjetImage en tant que BitMap au préalable Objet.Width -= 10 Objet.Height-= 10 Objet.Image = ObjetImage.GetThumbnailImage(Objet.Width, Objet.Height, CallBack, New IntPtr) Objet.Region = New System.Drawing.Region(Transparent(Objet.Image)) End Sub
pour réduire mon image en fonction de la taille de mon objetC'est du gaspillage inutile de ressources que d'utiliser des conteneurs picturebox pour déplacer des images. Mais soit.