Ich habe versucht, viele Texte in Bild zu zeichnen, aber es bekomme Fehler Ich möchte Benutzer in Bild mit einem beliebigen Pfad auswählen und speichern Sie das Ergebnis im selben Pfad mit einem anderen Namen das ist mein CodeWie zeichne Text in Bild mit C#
offen dialoge Taste
private void button1_Click(object sender, EventArgs e)
{
OpenFileDialog of1 = new OpenFileDialog();
of1.Filter = "JPEG|*.jpg|PNG|*.png|GIF|*.gif|BMP|*.bmp";
if ((of1.ShowDialog())==System.Windows.Forms.DialogResult.OK) {
imagepath = of1.FileName; //image path
}
}
Zeichnung Taste
private void button2_Click(object sender, EventArgs e)
{
string firstText = "G";
string secondText = "X";
string thirdText = "H";
string fourthText = "Z";
string fifthText = "Y";
string sixthText = "K";
string seventhText = "F";
string eighthText = "E";
PointF GLocation = new PointF(60f, 15f);
PointF XLocation = new PointF(145f, 15f);
PointF HLocation = new PointF(200f, 15f);
PointF ZLocation = new PointF(188f, 110f);
PointF YLocation = new PointF(7f, 100f);
PointF KLocation = new PointF(145f, 110f);
PointF FLocation = new PointF(213f, 96f);
PointF ELocation = new PointF(140f, 138f);
string imageFilePath = imagepath;
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, GLocation);
graphics.DrawString(secondText, arialFont, Brushes.Red, XLocation);
graphics.DrawString(thirdText, arialFont, Brushes.Blue, HLocation);
graphics.DrawString(fourthText, arialFont, Brushes.Red, ZLocation);
graphics.DrawString(fifthText, arialFont, Brushes.Blue, YLocation);
graphics.DrawString(sixthText, arialFont, Brushes.Red, KLocation);
graphics.DrawString(seventhText, arialFont, Brushes.Blue, FLocation);
graphics.DrawString(eighthText, arialFont, Brushes.Red, ELocation);
}
}
bitmap.Save(imageFilePath);//save the image file
}
Fehler ist
Ein Grafikobjekt kann nicht aus einem Bild mit einem indizierten Pixelformat erstellt werden.
eine einfache Google-Suche nach dem genauen Fehler 'C# Ein Grafik-Objekt kann nicht aus einem Bild, das ein indiziertes Pixel-Format hat erstellt werden und es wird Tonnen von Beispielen haben, wie Sie Ihr Problem zu korrigieren .. viel Glück – MethodMan
Mögliche Duplikat von [Grafiken auf indiziertem Bild] (http://Stackoverflow.com/questions/17313285/graphics-on-indexed-image) – MarkusEgle
@MethodMan wenn du mir helfen kannst wenn nicht danke :) – Amr