estoy usando el siguiente código para dibujar texto en un mapa de bits:¿Es posible definir un tamaño de fuente preciso al dibujar texto usando GDI +?
using (Font font = new Font("Arial", 10.0f, FontStyle.Bold, GraphicsUnit.Point))
{
//draw the text
graphics.DrawString("Some text", font, Brushes.White, rect, stringFormat);
}
Funciona bien. Aquí está el texto renderizada:
Quiero hacer el texto un poco más grande. Si fijo 11 como tamaño de fuente, esto es lo que me sale:
Es demasiado grande para lo que quiero. Probé 10.25, 10.5 y tal, pero da mismo resultado que
10.también trato de establecer GraphicsUnit
a Pixel
pero se comporta de la misma (sin posibilidad de ajustar el tamaño de fuente personalizado).
Aquí es mi pregunta:
Al dibujar texto utilizando GDI + (C#), hay una posibilidad de tamaño "ajuste fino" de texto representado?
EDIT: más completa fragmento de código (según lo solicitado):
using (Bitmap bitmap = new Bitmap(width, height))
using (Graphics graphics = Graphics.FromImage(bitmap))
using (Font font = new Font("Arial", 10.0f, FontStyle.Bold, GraphicsUnit.Point))
{
graphics.SmoothingMode = SmoothingMode.AntiAlias;
graphics.PixelOffsetMode = PixelOffsetMode.HighQuality;
Rectangle rect = new Rectangle(0, 0, width, height);
//method 1
StringFormat stringFormat = new StringFormat();
stringFormat.Alignment = StringAlignment.Center;
stringFormat.LineAlignment = StringAlignment.Center;
graphics.DrawString("Some text", font, Brushes.White, rect, stringFormat);
//method 2
TextFormatFlags flags = TextFormatFlags.HorizontalCenter |
TextFormatFlags.VerticalCenter | TextFormatFlags.WordBreak;
TextRenderer.DrawText(graphics, "Some text", font, rect, Color.White, flags);
bitmap.Save(stream, ImageFormat.Png);
}
Try 'TextRenderingHint.ClearTypeGridFit' – leppie
me trató graphics.TextRenderingHint = TextRenderingHint.ClearTypeGridFit, pero da los mismos resultados que – tigrou
sospecha que su' StringFormat' está mal. IIRC, utilicé 'FitBlackBox' con éxito. De hecho, modifiqué el ancho de la fuente para que sea exactamente un número entero, basado en configuraciones de altura muy específicas. – leppie