This article mainly introduced the text file content or text saved as a picture of the method, the need for friends can refer to the following
Calling method: The code is as follows: Converttextfiletoimage (Server.MapPath ("~/log.txt"), Server.MapPath ("~/log.png")); Implementation code: Code as follows: void Converttextfiletoimage (String textfile,string imagefile) {System.Drawing.Font Drawfont = new System.Drawing.Font ("Song Body", 12); System.Drawing.Bitmap image = New System.Drawing.Bitmap (1, 1); System.Drawing.Graphics g = System.Drawing.Graphics.FromImage (image); String Text = System.IO.File.ReadAllText (textfile, encoding.getencoding ("GB2312")); System.Drawing.SizeF SF = g.measurestring (text, Drawfont, 1024); Sets a display width image = new System.Drawing.Bitmap (image, New System.Drawing.Size (SF. Width), Convert.ToInt32 (SF. Height))); g = System.Drawing.Graphics.FromImage (image); G.clear (System.Drawing.Color.White); G.textrenderinghint = System.Drawing.Text.TextRenderingHint.AntiAliasGridFit; g.DrawString (text, Drawfont, System.Drawing.Brushes.Black, New System.Drawing.RectangleF (New System.Drawing.PointF ( 0, 0), SF)); Image. Save (ImageFile, System.drawIng. IMAGING.IMAGEFORMAT.PNG); G.dispose (); Image. Dispose (); }