Friday, May 15, 2020

Create Text into the Picture


CREATE TEXT PICTURE USING STRING


Create Bitmap Picture using String | Picture using String | Bitmap with C# String | Draw a text using C# | Create Picture of Text using C# | Create Text into the Picture


//using System.Drawing;
        //using System.Drawing.Text;
        //using System.Drawing.Drawing2D;
        //using System.Drawing.Imaging;
        public void create_image_from_text(string text)//pass string value
        {
            Bitmap bitmap = new Bitmap(1, 1);//create object of bitmap class
            Font font = new Font("Arial", 25, FontStyle.Regular, GraphicsUnit.Pixel);//set font, size
            Graphics graphics = Graphics.FromImage(bitmap);//pass object to graphics class
            int width = (int)graphics.MeasureString(text, font).Width;//set width
            int height = (int)graphics.MeasureString(text, font).Height;//set height
            bitmap = new Bitmap(bitmap, new Size(width, height));//bind height & width with object
            graphics = Graphics.FromImage(bitmap);//create image
            graphics.Clear(Color.Transparent);//set image transparent, if not then choose back color
            graphics.SmoothingMode = SmoothingMode.AntiAlias;//pic smoothness
            graphics.TextRenderingHint = TextRenderingHint.AntiAlias;
            graphics.DrawString(text, font, new SolidBrush(Color.FromArgb(0, 0, 0)), 0, 0);//set font color
            graphics.Flush();//free memory
            graphics.Dispose();//reset
            string fileName = text + ".png";//set filename
            bitmap.Save(Server.MapPath("~/AppFiles/") + fileName, ImageFormat.Png);//save to path
            bitmap.Dispose();//reset
        }


No comments:

Post a Comment

Note: Only a member of this blog may post a comment.

SQL Server Unique Constraint

SQL Server Unique Constraint Whats is Unique Constraint in SQL | How to create Unique Constraint in SQL | Unique Constraint with Example in ...