I am making my own captcha image and I have it pretty much working, but I can't figure out how to align the text in the image. I tried using a stringformat, but I can't quite get it lined up right. If someone could tell me where I am going wrong, it would help me out a lot.
Here is the code I am working with.
Thank you.Code:Private Sub CreateImage() Dim equation As String = GetEquation() Dim bitMap As New Bitmap(150, 30, Imaging.PixelFormat.Format32bppArgb) Dim font As New Font("Arial", 22, FontStyle.Bold, GraphicsUnit.Pixel) Dim rect As New Rectangle(0, 0, 150, 30) Dim sf As New StringFormat(StringFormatFlags.NoWrap) sf.Alignment = StringAlignment.Center sf.LineAlignment = StringAlignment.Center Dim g As Graphics = Graphics.FromImage(bitMap) Dim b As New SolidBrush(Color.LightBlue) Dim pen As New Pen(Color.Black) g.SmoothingMode = Drawing2D.SmoothingMode.AntiAlias g.FillRectangle(Brushes.Beige, rect) g.DrawRectangle(pen, rect) g.DrawString(equation, font, Brushes.Blue, 0, 0, sf) Response.ContentType = "image/jpeg" bitMap.Save(Response.OutputStream, Imaging.ImageFormat.Jpeg) g.Dispose() bitMap.Dispose() End Sub




Reply With Quote