A
Academia
I need to create a Bitmap just big enough to display a string.
Since I need a Graphic object to measure the string I create and dispose a
Bitmap and a Graphic object only for that purpose.
Isn't there a better way of doing this than with the code below?
Thanks
Dim bit As Bitmap = New Bitmap(SomeWidth, SomeHeight)
Dim gr As Graphics = Picture.CreateGraphics(Nothing, bit)
Dim f As Font = New Font("Arial", 10)
Dim b As Brush = New SolidBrush(Color.Black)
Dim s As Size = gr.MeasureString(strng, f).ToSize
bit.dispose()
bit = New Bitmap(s.Width, s.Height)
gr.dispose()
gr = Picture.CreateGraphics(Nothing, bit)
Gr.DrawString(Strng, f, b, 0, 0)
Since I need a Graphic object to measure the string I create and dispose a
Bitmap and a Graphic object only for that purpose.
Isn't there a better way of doing this than with the code below?
Thanks
Dim bit As Bitmap = New Bitmap(SomeWidth, SomeHeight)
Dim gr As Graphics = Picture.CreateGraphics(Nothing, bit)
Dim f As Font = New Font("Arial", 10)
Dim b As Brush = New SolidBrush(Color.Black)
Dim s As Size = gr.MeasureString(strng, f).ToSize
bit.dispose()
bit = New Bitmap(s.Width, s.Height)
gr.dispose()
gr = Picture.CreateGraphics(Nothing, bit)
Gr.DrawString(Strng, f, b, 0, 0)