How to write something on image in windows form c#

Using Graphics class we can write something on image. Graphics class object invoke drawing objects, like String, Rectangle, oval etc. For DrawString( ) method, we need some parameter like string text, font, point where you want to display string on image. Now copy this code



            Image img = new Bitmap(this.pictureBox1.Width, this.pictureBox1.Height);

            var font = new Font("TimesNewRoman", 25, FontStyle.Bold, GraphicsUnit.Pixel);

            var graphics = Graphics.FromImage(img);

            graphics.DrawString("Hello World! " , font, Brushes.Red, new Point(0, 0));

            this.pictureBox1.Image = img;

Here

  1. First to add the picture box in the form.
  2. Now, using the Bitmap class we can pick the resolution parameter of picture box then assign these parameter to Image class instance.
  3. Take Font class for making highly visualize text in the image.
  4. Use graphics class to Draw the string on the image.
  5. Before Drawing must to assign the image to the Graphics class.
The following mentioned video contain full implementation guide:



0 comments:

Post a Comment