Les Snippets

Connexion

Placer une image n’importe où dans un picturebox (ou n'importe ou dans un control)

Niveau requis pour utiliser/comprendre cette source : 1 ( Débutant )
Créé le 22/03/2006 14:20:15 et initié par Charles Racaud [Liste]
Vue : 9165
Catégorie(s) : Graphique
Langages dispo pour ce code :
- C# 2.x
- VB 2005



Langage : C# 2.x
Date ajout : 22/03/2006
Posté par Charles Racaud [Liste]
private System.Drawing.Image SetPictureAtPoint(System.Drawing.Size FinalImageSize, System.Drawing.Image Image, System.Drawing.Point Location)
{
  System.Drawing.Image TmpImg = new System.Drawing.Bitmap(FinalImageSize.Width, FinalImageSize.Height); // Image finale
  System.Drawing.Graphics Graphics = System.Drawing.Graphics.FromImage(TmpImg); // Récupére un graphics de l'image
  Graphics.DrawImage(Image, Location); // Dessine l'image sur le graphics
  return TmpImg;
}
private System.Drawing.Image SetPictureAtPoint(System.Drawing.Image Image, System.Drawing.Point Location)
{
  System.Drawing.Image TmpImg = new System.Drawing.Bitmap(Location.X + Image.Width, Location.Y + Image.Height); // Image finil avec la taille adapter
  System.Drawing.Graphics Graphics = System.Drawing.Graphics.FromImage(TmpImg); // Récupére un graphics de l'image
  Graphics.DrawImage(Image, Location); // Dessine l'image sur le graphics
  return TmpImg;
}

Example d'utilisation: Placement d'une image a la position (10, 10) dans une PictureBox:
Bitmap Img = new Bitmap("LeChemin\\DeVotre\\FichierImage");
this.pictureBox1.Image = SetPictureAtPoint(img, new System.Drawing.Point(10, 10));
Remarque :
Ici, on a deux fonctions : Une ou la taille final de l’image est choisi, l’autre ou elle est adapté en fonction de la position et de la taille de l’image d’origine.
Langage : VB 2005
Date ajout : 22/03/2006
Posté par Charles Racaud [Liste]

Private Function SetPictureAtPoint(ByVal FinalImageSize As System.Drawing.Size, ByVal Image As System.Drawing.Image, ByVal Location As System.Drawing.Point) As System.Drawing.Image
  Dim TmpImg As System.Drawing.Image = New System.Drawing.Bitmap(FinalImageSize.Width, FinalImageSize.Height) 'Image finale
  Dim Graphics As System.Drawing.Graphics = System.Drawing.Graphics.FromImage(TmpImg) 'Récupère un graphics de l'image
  Graphics.DrawImage(Image, Location) 'Dessine l'image sur le graphics
  Return TmpImg
End Function
Private Function SetPictureAtPoint(ByVal Image As System.Drawing.Image, ByVal Location As System.Drawing.Point) As System.Drawing.Image
  Dim TmpImg As System.Drawing.Image = New System.Drawing.Bitmap(Location.X + Image.Width, Location.Y + Image.Height) 'Image finil avec la taille adapter
  Dim Graphics As System.Drawing.Graphics = System.Drawing.Graphics.FromImage(TmpImg) 'Récupère un graphics de l'image
  Graphics.DrawImage(Image, Location) 'Dessine l'image sur le graphics
  Return TmpImg
End Function
Example d'utilisation: Placement d'une image a la position (10, 10) dans une PictureBox:
Dim Img As New Bitmap("LeChemin\DeVotre\FichierImage")
Me.PictureBox1.Image = SetPictureAtPoint(Img, New System.Drawing.Point(10, 10))

Remarque :
Ici, on a deux fonctions : Une ou la taille final de l’image est choisi, l’autre ou elle est adapté en fonction de la position et de la taille de l’image d’origine.

Snippets en rapport avec : Image, Graphics, Picturebox, Placer, Position



Codes sources en rapport avec : Image, Graphics, Picturebox, Placer, Position

{Visual Basic, VB6, VB.NET, VB 2005} RÉORGANISER UNE LISTVIEW AVEC DES IMAGES DANS LES 3 PREMIÈRES COLONES
Cette source est la première que je dépose donc j'attends vos commentaires. Mon but était de réussi...

{Visual Basic, VB6, VB.NET, VB 2005} DRAG AND DROP IMAGE INTERNET
J'ai eu du mal a le faire donc je le met car cela peut etre utile pour mettre des images dans une ba...

{Visual Basic, VB6, VB.NET, VB 2005} ENREGISTRER L'IMAGE D'UN CONTRÔLE
Cette fonction enregistre l'image d'un contrôle (bouton, Label, MSChart ...) dans un fichier image....

{Visual Basic, VB6, VB.NET, VB 2005} INSÉRER UNE LIGNE GRAPHICS DANS UNE RICHTEXTBOX
Ce code permet de montrer simplement comment créer des éléments graphics et les insérer dans une Ric...

{Visual Basic, VB6, VB.NET, VB 2005} REDIMENSION D'IMAGE
Voici un petit logiciel simple de redimension d'image : - en gardant les proportions ou non - en c...

{Visual Basic, VB6, VB.NET, VB 2005} AFFICHE ET ENREGISTRE UNE IMAGE D'UNE WEBCAM (SNAPSHOT) À FRÉQUENCE DÉSIRÉE
En quelques lignes, ce code va d'abord chercher l'image dans la WEBCam puis l'enregistre sur le DD a...

{JAVA / J2EE} TRAITEMENT IMAGE
Voici un petit bout de code. Rien de bien sorcier, j'ai juste récupérer des sources trouvée à droit...

{Visual Basic, VB6, VB.NET, VB 2005} PICTUREBOX "INTELLIGENT" (DU MOINS PLUS QUE CELUI LIVRÉ EN STANDARD :)
Ce control utilisateur est une picture box qui permet d'afficher une image en la redimensionnant afi...

{Visual Basic, VB6, VB.NET, VB 2005} CRÉE UNE IMAGE À PARTIR D'UN GRAPHICS
Depuis le temps que je cherchais comment crée une image à partir d'un Graphics ! Ben, j'ai enfin tr...

{C# / C#.NET} ZOOM D'UNE IMAGE AVEC L'AFFICHAGE DE SCROOLBARS LE PLUS SIMPLE POSSIBLE
Salut Sur une demande de Moucave dans le forum, voila un tit prog pour zoomer, pour les scrool bar...