Drawing text on image

后端 未结 1 1073
遥遥无期
遥遥无期 2021-01-18 09:47

I have never worked with drawing before and im having a little issue. I cant seem to get the output of this code to work.

The file is saving but it is not drawing o

相关标签:
1条回答
  • 2021-01-18 10:20

    I am sure you might be looking for this.

    rectf = new RectangleF(655, 460, 535, 90); //rectf for My Text
    using(Graphics g = Graphics.FromImage(myBitmap))
    {
        //g.DrawRectangle(new Pen(Color.Red, 2), 655, 460, 535, 90); 
        g.SmoothingMode = SmoothingMode.AntiAlias;
        g.InterpolationMode = InterpolationMode.HighQualityBicubic;
        g.PixelOffsetMode = PixelOffsetMode.HighQuality;
        StringFormat sf = new StringFormat();
        sf.Alignment = StringAlignment.Center;
        sf.LineAlignment = StringAlignment.Center;
        g.DrawString("My\nText", new System.Drawing.Font("Tahoma", 32, FontStyle.Bold), Brushes.Black, rectf, sf);
    }
    

    //g.DrawRectangle(new Pen(Color.Red, 2), 655, 460, 535, 90); Line is used to show where your text will be written. So before you actually make your make your text You can see where this rectanlge will be created on the image. If you want the center of the image you can find the height and width and divide that by 2 to find the center of the image and than can plot the rectangle parameters accordingly.

    0 讨论(0)
提交回复
热议问题