Ecrire sur une image, problème d'anti-aliasing
Bonjour,
J'ai décidément un problème avec les images. Le code suivant crée une nouvelle image à partir d'une image originale et d'un texte qui s'écrira en-dessous. Le code fonctionne très bien, à un problème près. Le texte s'écrit dans une fonte toute "pas belle". On dirait que le style est défini à gras, alors que pas du tout. Un collègue me dit que ça vient d'un problème d'anti-aliasing. L'ennui, c'est que je ne sais pas comment régler ça.
Quelqu'un aurait la solution pour me dépanner ?
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
|
public static System.Drawing.Bitmap LibelledImage(System.Drawing.Bitmap originalImage, string text, System.Drawing.Font font,
System.Drawing.Size size, int imageHeight)
{
int textHeight = size.Height - imageHeight;
// Create target bitmap to return
System.Drawing.Bitmap targetBmp = new System.Drawing.Bitmap(size.Width, size.Height,
System.Drawing.Imaging.PixelFormat.Format32bppArgb);
System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(targetBmp);
// Calculate image origin point and draw image
System.Drawing.Point originImage = new System.Drawing.Point();
originImage.X = (size.Width - originalImage.Width) / 2;
originImage.Y = (imageHeight - originalImage.Height) / 2;
g.DrawImage(originalImage, originImage);
// Define format to draw text
System.Drawing.StringFormat format = new System.Drawing.StringFormat();
format.LineAlignment = System.Drawing.StringAlignment.Center;
format.Alignment = System.Drawing.StringAlignment.Center;
// Draw text in RectangleF
System.Drawing.RectangleF rectText = new System.Drawing.RectangleF(0, imageHeight, size.Width, textHeight);
System.Drawing.Font ft = new System.Drawing.Font(font.Name, 8.25f, System.Drawing.FontStyle.Regular);
g.DrawString(text, ft, System.Drawing.Brushes.Black, rectText, format);
return targetBmp;
} |
Merci d'avance
Papy !