cs_Seb33300
Messages postés84Date d'inscriptionmardi 20 septembre 2005StatutMembreDernière intervention 7 février 2010
-
2 avril 2006 à 19:46
LAYLO1010 -
27 janv. 2009 à 12:15
Bonjour,
Je voudrais placer sur une PictureBox plusieurs images à partir de fichiers images
Pour chacune d'elles je doit pouvoir dire si elle doit se placer au premier plan ou au dernier plan et à quelle position sur le picturebox (x,y en pixel)
Pour le moment j'utilise :
Dim image As System.Drawing.Image
image = System.Drawing.Bitmap.FromFile(lstCards().SelectedItem)
Mais si j'ajoute une deuxieme image de la meme facon, l'image remplace la premiere.
On récupére l'image de ta picturebox, on dessine une nouvelle image par dessus est on redéfini la final comme nouvelle
Ca donne une petite fonction:
Private Sub AddImageToPicture(ByVal Img As System.Drawing.Image, ByVal Location As System.Drawing.Point)
Dim FinalImg As System.Drawing.Image = New System.Drawing.Bitmap(Me.PictureBox1.Width, Me.PictureBox1.Height)
Dim Graphics As System.Drawing.Graphics = System.Drawing.Graphics.FromImage(FinalImg)
If Me.PictureBox1.Image IsNot Nothing Then
Graphics.DrawImage(Me.PictureBox1.Image, System.Drawing.Point.Empty)
End If
Graphics.DrawImage(Img, Location)
Me.PictureBox1.Image = FinalImg
End Sub
Example d'utilisation:
Call AddImageToPicture(Image.FromFile(
"Chemin/de/ton/Image01"), New System.Drawing.Point(10, 10))
Call AddImageToPicture(Image.FromFile(
"Chemin/de/ton/Image02"), New System.Drawing.Point(40, 20))
Call AddImageToPicture(Image.FromFile(
"Chemin/de/ton/Image03"), New System.Drawing.Point(30, 30))
[...]
Kenji
<HR width="100%" SIZE=2>
Merci de cliquer sur "Réponse acceptée" si une réponse vous convient.
Tu peux dessiner un peut n'importe quoi sur ta picture (Image, Text,Formes ...)
Private Sub AddTextToPicture(ByVal Text As String, ByVal Location As System.Drawing.Point, ByVal Brush As System.Drawing.Brush, ByVal Font As System.Drawing.Font)
Dim FinalImg As System.Drawing.Image = New System.Drawing.Bitmap(Me.PictureBox1.Width, Me.PictureBox1.Height)
Dim Graphics As System.Drawing.Graphics = System.Drawing.Graphics.FromImage(FinalImg)
If Not Me.PictureBox1.Image Is Nothing Then
Graphics.DrawImage(Me.PictureBox1.Image, System.Drawing.Point.Empty)
End If
Graphics.DrawString(Text, Font, Brush, Location)
Me.PictureBox1.Image = FinalImg
End Sub
Et n'oublie pas les "réponses acceptées"
Kenji
<HR width="100%" SIZE=2>
Merci de cliquer sur "Réponse acceptée" si une réponse vous convient.
La, il faut placer des contrôles textbox sur la picture:
Private TextBoxList As System.Collections.ArrayList
Private Sub AddTextBoxToPicture(ByVal Bounds As System.Drawing.Rectangle)
If TextBoxList Is Nothing Then TextBoxList = New System.Collections.ArrayList()
Dim TxtBox As New System.Windows.Forms.TextBox()
TxtBox.Bounds = Bounds
Me.PictureBox1.Controls.Add(TxtBox)
TextBoxList.Add(TxtBox)
End Sub
Kenji
<HR width="100%" SIZE=2>
Merci de cliquer sur "Réponse acceptée" si une réponse vous convient.
Je poste quand même. Ca peut-être utile.
Avec la fonction précédente pour les TextBox:
Private TextBoxList As System.Collections.ArrayList
Private Sub AddTextBoxToPicture(ByVal Bounds As System.Drawing.Rectangle)
If TextBoxList Is Nothing Then TextBoxList = New System.Collections.ArrayList()
Dim TxtBox As New System.Windows.Forms.TextBox()
TxtBox.Bounds = Bounds
Me.PictureBox1.Controls.Add(TxtBox)
TextBoxList.Add(TxtBox)
End Sub
Private Function GetBitmap() As System.Drawing.Image
If Not Me.PictureBox1.Image Is Nothing Then
Dim Img As System.Drawing.Image = Me.PictureBox1.Image
Dim Graphics As System.Drawing.Graphics = System.Drawing.Graphics.FromImage(Img)
For Each TxtBox As System.Windows.Forms.TextBox In TextBoxList
Dim TxtImage As New System.Drawing.Bitmap(TxtBox.Width, TxtBox.Height)
TxtBox.DrawToBitmap(TxtImage, TxtBox.ClientRectangle)
Graphics.DrawImage(TxtImage, TxtBox.Location)
Next
Return Img
End If
Return Nothing
End Function
Kenji
<HR width="100%" SIZE=2>
Merci de cliquer sur "Réponse acceptée" si une réponse vous convient.
cs_Seb33300
Messages postés84Date d'inscriptionmardi 20 septembre 2005StatutMembreDernière intervention 7 février 2010 5 avril 2006 à 19:17
Salut c'est encore moi
Peut etre pourra tu me renseigner :
Quand j'ajoute une image au format .png avec ta fonction AddImageToPicture
celle ci s'ajoute correctement par contre si j'ajoute de la transparence sur les contours de cette image et que j'utilise la fonction la taille de l'image que j'ajoute s'agrandi
Par contre si je la convertie au format gif, il n'y a pas de probleme
Effectivement, même problême
Oui, le pb vient peut-être du format png.
Sinon, ca sa marche, la même fonction avec en plus la taille final de l'image
Private Sub AddImageToPicture(ByVal Img As System.Drawing.Image, ByVal Location As System.Drawing.Point, ByVal Size As System.Drawing.Size)
Dim FinalImg As System.Drawing.Image = New System.Drawing.Bitmap(Me.PictureBox1.Width, Me.PictureBox1.Height)
Dim Graphics As System.Drawing.Graphics = System.Drawing.Graphics.FromImage(FinalImg)
If Me.PictureBox1.Image IsNot Nothing Then
Graphics.DrawImage(Me.PictureBox1.Image, System.Drawing.Point.Empty)
End If
Graphics.DrawImage(Img, New System.Drawing.Rectangle(Location, Size))
Me.PictureBox1.Image = FinalImg
End Sub
Kenji
<HR width="100%" SIZE=2>
Merci de cliquer sur "Réponse acceptée" si une réponse vous convient.