Click here to Skip to main content
15,886,362 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have converted given string to JPG file format. But i need those image string in center. Iam getting output from leftside of rectangle.
VB
Dim stext As String = "Testing"
           Dim format As StringFormat = New StringFormat()
           Dim MyRect As Rectangle = New Rectangle(0, 0, 400, 800)
           Dim MyGraphics As Graphics = Me.CreateGraphics()
           Dim MyImg As Image = New Bitmap(391, 132, MyGraphics)
           Dim imageGraphics As Graphics = Graphics.FromImage(MyImg)
           imageGraphics.FillRectangle(Brushes.White, MyRect)
           format.Alignment = StringAlignment.Center
           format.LineAli`enter code here`gnment = StringAlignment.Center
           imageGraphics.DrawString("Testing", New Font("Times New Roman", 30, Drawing.FontStyle.Bold), Brushes.Black, RectangleF.op_Implicit(MyRect))
           MyGraphics.DrawImage(MyImg, MyRect)
           MyImg.Save(Destfilename & "/"  & "test.jpg")


I have given this code output. But i need this string to in center position. How to do, Kindly help me through.
Output: https://drive.google.com/file/d/0B_nzYHWVJJ7Ka3N0V2NmRnl3UFk/view?usp=sharing[^]
Posted
Updated 1-Mar-15 21:18pm
v2
Comments
Matej Hlatky 2-Mar-15 14:19pm    
Hi, have you tried to use different Graphics.DrawString method - the one with the rectangle parameter?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900