동적으로 텍스트를 기존 이미지에 추가하고 있습니다. 내가 낯선 것을 찾고 있지만 펜/브러쉬/글꼴을 사용할 때 텍스트가 더 얇아지는 것처럼 보입니다.Drawing.Font는 사용마다 더 얇게 나타납니다.
코드 스 니펫을 보는 것이 더 쉬울 수 있습니다.
아래 코드에서 사용되지 않은 일부 변수가 아래 코드에 선언되어 있습니다.이 코드는 대부분 그 질문과 관련이없는 큰 코드 조각입니다. 이 부분은 텍스트를 쓰는 부분입니다.
궁극적으로 모든 리소스가 블록을 사용하여 만들어집니다.
다음은 아래에 표시된 AddTextToGraphicsPath()
방법으로갑니다. 이렇게하면 텍스트가 경로에 적용됩니다.
그리고 사용
Using fiTextFont As New Font("Arial"), FontStyle.Bold)
Using brush As Brush = New SolidBrush(ColorTranslator.FromHtml("#000000"))
Using pen As Pen = New Pen(ColorTranslator.FromHtml("transparent"))
Using oImage As Image = Image.FromFile(fName)
Using grfx As Graphics = Graphics.FromImage(oImage)
For i As Integer = 0 To loopCount
Using gPath As GraphicsPath = New GraphicsPath()
grfx.SmoothingMode = Drawing2D.SmoothingMode.HighQuality
grfx.TextRenderingHint = Drawing.Text.TextRenderingHint.ClearTypeGridFit
grfx.CompositingQuality = CompositingQuality.HighQuality
Dim sFormat As New StringFormat(StringFormat.GenericTypographic)
sFormat.Alignment = StringAlignment.Center
Dim textSplit() As String = fiText.Split(vbCrLf)
AddTextToGraphicsPath(gPath, grfx, textSplit(0).Replace(vbLf, ""), fiTextFont, fxPos, fyPos, pen, brush, Nothing, sFormat)
AddTextToGraphicsPath(gPath, grfx, textSplit(1).Replace(vbLf, ""), fiTextFont, fxPos, fyPos + fiTextFont.Size - 2, pen, brush, Nothing, sFormat)
End Using
Next
End Using
End Using
End Using
End Using
끝 경로에 텍스트를 적용하는 방법입니다.
Private Shared Sub AddTextToGraphicsPath(ByRef gPath As GraphicsPath, ByRef grfx As Graphics, ByRef text As String, ByRef font As Font, ByRef x As Single, ByRef y As Single, ByRef pen As Pen, ByRef brush As Brush, ByRef matrix As Matrix, ByRef sFormat As StringFormat)
gPath.AddString(text, font.FontFamily, font.Style, font.Size, New PointF(x, y), sFormat)
If (matrix IsNot Nothing) Then gPath.Transform(matrix)
grfx.DrawPath(pen, gPath)
grfx.FillPath(brush, gPath)
End Sub
Eveything 완벽하게 잘 작동 - 두 번째 줄은 무게가 훨씬 가벼운 것 같다하지만 텍스트는 올바른 위치에 등 글꼴 올바른 적용됩니다.
글꼴을 Bold
으로 설정하면 첫 번째 줄은 굵게 표시되고 두 번째 줄은 "나타납니다"라고 표시되는데 코드를 반복하면 글꼴이 바뀌지 않습니다.
그리고 결과 이미지는 아래의 예와 같은 작은 선물 같습니다
UPDATE 지금 동일한 코드를했지만, 새로운 글꼴, 펜, 브러시를 만든
을 AddTestToGraphicsPath에 대한 각각의 호출은 여전히 동일합니다. 그래서 이것이 GraphicsPath.AddString() 문제 일까 궁금?