It will be better to see more of your code, but as I understand it from the TextRenderer class, this is System.Windows.Forms. Just don't use Graphics created from a control (suppose it's a pictureBox with sizemode: Zoom), use Graphics created from your image.
Here is the code (sorry, C #) that loads the image from the file, draws the text, starting from the same coordinate and location on puctureBox1. Text always starts with a period (100 100).
OpenFileDialog openFileDialog1 = new OpenFileDialog(); openFileDialog1.Filter = "Image files|*.jpeg;*.png;*.jpg;*.gif;*.bmp"; if(openFileDialog1.ShowDialog() == DialogResult.OK) { try { Bitmap orig=(Bitmap)Bitmap.FromFile(openFileDialog1.FileName); //workaround for images with color table, see remarks here https://msdn.microsoft.com/en-us/library/system.drawing.graphics.fromimage(v=vs.110).aspx Bitmap bmp=orig.Clone(new Rectangle(0, 0, orig.Width, orig.Height), System.Drawing.Imaging.PixelFormat.Format32bppPArgb); Graphics g = Graphics.FromImage(bmp); g.DrawString("hello", new Font(this.Font.FontFamily,30,FontStyle.Bold ) , new System.Drawing.SolidBrush(System.Drawing.Color.Yellow ), new Point(100, 100)); this.pictureBox1.Image = bmp; orig.Dispose(); } catch (Exception ex) { MessageBox.Show("Something goes wrong: " + ex.Message+ "\\n"+ ex.StackTrace ); } }
source share