Per esempio la 'A' scritta col Carattere "Sans Serif" di dimensione "8" in grassetto, ha come misure del rettangolo circoscritto 10 x 8 (misure date a caso). Per ora mi sono fatto un algoritmino io ma, se esistesse un metodo migliore...
Codice PHP:
Function fitChar(ByVal imgChar As Bitmap, ByVal BackColor As Color) As Bitmap
Dim x As Integer, y As Integer
Dim xBlank As Integer = imgChar.Width, yBlank As Integer = imgChar.Height
Dim Blank As Boolean = True
Dim retBmp As Bitmap
For x = imgChar.Width - 1 To 0 Step -1
For y = imgChar.Height - 1 To 0 Step -1
If imgChar.GetPixel(x, y).A = BackColor.A And imgChar.GetPixel(x, y).R = BackColor.R And imgChar.GetPixel(x, y).G = BackColor.G And imgChar.GetPixel(x, y).B = BackColor.B Then
Blank = Blank And True
Else
Blank = Blank And False
End If
Next
If Blank = True Then
xBlank = x
Else
Exit For
End If
Next
Blank = True
For y = imgChar.Height - 1 To 0 Step -1
For x = imgChar.Width - 1 To 0 Step -1
If imgChar.GetPixel(x, y).A = BackColor.A And imgChar.GetPixel(x, y).R = BackColor.R And imgChar.GetPixel(x, y).G = BackColor.G And imgChar.GetPixel(x, y).B = BackColor.B Then
Blank = Blank And True
Else
Blank = Blank And False
End If
Next
If Blank = True Then
yBlank = y
Else
Exit For
End If
Next
If xBlank = 0 Then
xBlank = imgChar.Width
End If
If yBlank = 0 Then
yBlank = imgChar.Height
End If
retBmp = New Bitmap(xBlank, yBlank)
For x = 0 To xBlank - 1
For y = 0 To yBlank - 1
retBmp.SetPixel(x, y, imgChar.GetPixel(x, y))
Next
Next
Return retBmp
End Function
per esempio
Immagine dove stampo : 48 x 48 pixel (scelti per caso)
Risulta:

Ma se esistesse un metodo dove possa sapere a priori la dimensione del carattere....