I want to draw a text on image. However text is not centered on the image. What can I do? I set the coordinate x=0, y=0; But text is shifted...
Bitmap image = new Bitmap(width, height);
RectangleF rectf = new RectangleF(0, 0, image.Width, image.Height);
using (Graphics g = Graphics.FromImage(image))
{
g.CompositingQuality = CompositingQuality.HighQuality;
g.InterpolationMode = InterpolationMode.HighQualityBicubic;
g.SmoothingMode = SmoothingMode.HighQuality;
g.PixelOffsetMode = PixelOffsetMode.HighQuality;
g.Clear(Color.Black);
StringFormat sf = new StringFormat();
sf.Alignment = StringAlignment.Near;
sf.LineAlignment = StringAlignment.Center;
g.DrawString(text, new Font("Times New Roman", fontSize), Brushes.Red, rectf, sf);
g.Flush();
}
return image;