Pour dessiner plusieurs chaînes, appelez graphics.DrawString
plusieurs fois. Vous pouvez spécifier l'emplacement de la chaîne dessinée. Dans cet exemple, nous allons dessiner deux chaînes "Hello", "Word" ("Hello" en couleur bleue devant "Word" en couleur rouge) :
string firstText = "Hello";
string secondText = "World";
PointF firstLocation = new PointF(10f, 10f);
PointF secondLocation = new PointF(10f, 50f);
string imageFilePath = @"path\picture.bmp"
Bitmap bitmap = (Bitmap)Image.FromFile(imageFilePath);//load the image file
using(Graphics graphics = Graphics.FromImage(bitmap))
{
using (Font arialFont = new Font("Arial", 10))
{
graphics.DrawString(firstText, arialFont, Brushes.Blue, firstLocation);
graphics.DrawString(secondText, arialFont, Brushes.Red, secondLocation);
}
}
bitmap.Save(imageFilePath);//save the image file
Edit : "J'ajoute un code de chargement et de sauvegarde".
Vous pouvez ouvrir le fichier bitmap à tout moment. Image.FromFile
et dessinez un nouveau texte dessus en utilisant le code ci-dessus, puis enregistrez le fichier image. bitmap.Save
6 votes
Quelle est votre question ? Quel est le problème que vous rencontrez ?
2 votes
Vous avez ajouté une question, mais n'avez pas décrit le problème réel que vous rencontrez en faisant cela.