0
Ich versuche, Bild von HTML-Code in C#, aber ich habe kein Bild. Können Sie mir bitte helfen, HTML-Code in Bild in C# -Code hinter zu konvertieren.Wie konvertiert man HTML-Code in Bilder mit Code hinter C#
Ich versuchte mit der Übergabe von HTML-Code-String in Bitmap, aber ich bekomme das nicht.
mailtxt = "<html><body><table><tr><td>Hello Sir</td></tr></table></body></html>";
StringBuilder str = new StringBuilder();str.Append(mailtxt.ToString());
Bitmap objBmpImage = new Bitmap(2, 2);
int intWidth = 0;
int intHeight = 0;
// Create the Font object for the image text drawing.
System.Drawing.Font objFont = new System.Drawing.Font("Arial", 10, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Pixel);
// Create a graphics object to measure the text's width and height.
Graphics objGraphics = Graphics.FromImage(objBmpImage);
// This is where the bitmap size is determined.
intWidth = (int)objGraphics.MeasureString(str.ToString(), objFont).Width;
intHeight = (int)objGraphics.MeasureString(str.ToString(), objFont).Height;
// Create the bmpImage again with the correct size for the text and font.
objBmpImage = new Bitmap(objBmpImage, new Size(intWidth, intHeight));
// Add the colors to the new bitmap.
objGraphics = Graphics.FromImage(objBmpImage);
// Set Background color
objGraphics.Clear(System.Drawing.Color.White);
objGraphics.SmoothingMode = SmoothingMode.HighQuality;
objGraphics.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAlias; // <-- This is the correct value to use. ClearTypeGridFit is better yet!
objGraphics.DrawString(str.ToString(), objFont, new SolidBrush(System.Drawing.Color.Black), 0, 0, StringFormat.GenericDefault);
objGraphics.Flush();
Vielen Dank im Voraus.
Gibt es einen Grund, warum Sie '' objBmpImage'' in den Konstruktor übergeben? '' objBmpImage = new Bitmap (objBmpImage, neue Größe (intWidth, intHeight)); '' warum erstellst du nicht eine komplett neue? –
Und nur aus Neugier wissen Sie, dass Sie ein Bild mit der Zeichenfolge "
..." usw. erhalten, und nicht das gerenderte HTML, wie es in einem Browser aussehen würde? Ist es das was du willst? Oder möchten Sie, dass der HTML-Code gerendert wird? –Danke für die Antwort Rand Random.Ich möchte Bild in gerenderten HTML. – Naganath