2017-10-16 12 views
-2

Vb.netを使用してテキストをImageに変換するコードで試していましたが、問題はユーザーからのメッセージを受け入れる必要があります(最大160文字)をテキストボックスで置き換え、それをImageに変換する必要があります。生成された画像は中央に配置され、画像の最大解像度は800x600でなければなりません。VB.netでテキストを自動整列して調整する方法

メッセージは、必要に応じて真ん中に完全に揃えて新しい行に整列させる必要があります。次のように

私がしようとしているコードは次のとおりです。

================================= =====================

Dim Text As String = TextBox3.Text 

    Dim FontColor As Color = Color.Blue 

    Dim BackColor As Color = Color.White 

    Dim FontName As String = "Times New Roman" 

     Dim FontSize As Integer = 36 


     Dim Height As Integer = 60 

     Dim Width As Integer = 200 

    Dim daten As String 
    daten = Now.ToString("ddMMyyyyhhmmss") 
    Dim FileName As String = daten 
    Dim objBitmap As New Bitmap(Width, Height) 
    Dim objGraphics As Graphics = Graphics.FromImage(objBitmap) 
    Dim objColor As Color 
    objColor = Nothing 

    Dim objFont As New Font(FontName, FontSize) 

    'Following PointF object defines where the text will be displayed in the 

    'specified area of the image 

    Dim objPoint As New PointF(5.0F, 5.0F) 
    Dim objBrushForeColor As New SolidBrush(FontColor) 

    Dim objBrushBackColor As New SolidBrush(BackColor) 
    objGraphics.FillRectangle(objBrushBackColor, 0, 0, Width, Height) 
    objGraphics.DrawString(Text, objFont, objBrushForeColor, objPoint) 
    objBitmap.Save("D:\DNB\" + daten + ".JPG", ImageFormat.Jpeg) 
     PictureBox1.Image = Image.FromFile("D:\DNB\" + daten + ".JPG") 
    Catch ex As Exception 

    End Try 
+0

ご覧ください[タグを誤って使用するのを避けるにはどうすればいいですか?](https://meta.stackoverflow.com/questions/354427/how-do-i-avoid-misusing-tags) – EJoshuaS

答えて

0

はあなたがGraphicsオブジェクトのMeasureString機能を試してみました試してみて、それが様々なオーバーライドですか?これにより、指定されたサイズとフォント内のテキストが画面上でどれくらいのスペースを必要としているかを測定できます。その知識によって、左上の点を計算してテキストを中央に表示させることができます。

関連する問題