Search code examples
c#winformsdrawing

Write text on bitmap


I have following problem. I want to make some graphics in c# windows form. I want to read bitmap to my program and after it write some text on this bitmap. In the end I want this picture load to pictureBox. And it's my question. How can I do it?

example, how must it work:

Bitmap a = new Bitmap(@"path\picture.bmp");
a.makeTransparent();
// ? a.writeText("some text", positionX, positionY);
pictuteBox1.Image = a;

Is it possible do to?


Solution

  • Bitmap bmp = new Bitmap("filename.bmp");
    
    RectangleF rectf = new RectangleF(70, 90, 90, 50);
    
    Graphics g = Graphics.FromImage(bmp);
    
    g.SmoothingMode = SmoothingMode.AntiAlias;
    g.InterpolationMode = InterpolationMode.HighQualityBicubic;
    g.PixelOffsetMode = PixelOffsetMode.HighQuality;
    g.DrawString("yourText", new Font("Tahoma",8), Brushes.Black, rectf);
    
    g.Flush();
    
    image.Image=bmp;