I'm trying to use GDI
in C#
to draw Code 128
barcode. I have .ttf
font which should work as vector graphic (not rastr):
var bmp = new Bitmap(900, 100);
var g = Graphics.FromImage(bmp);
g.Clear(Color.White);
g.SmoothingMode = SmoothingMode.None;
g.InterpolationMode = InterpolationMode.HighQualityBicubic;
g.PixelOffsetMode = PixelOffsetMode.HighQuality;
g.DrawString(value, new Font("Code 128", 72), Brushes.Black, 0, 50);
g.DrawPath(new Pen(Brushes.Black, (float) 1.0), new GraphicsPath());
g.Flush();
the result image is wide, i want to scale it to 0.5 (x axis only). But when i scale X to 450,- image becomes not clear. I noticed that image (when it still 900) is lightly blurred:
i think my broblem will be solved if image will look like here:
How to draw string in such manner?
Smoothing of text is controlled by the TextRenderingHint property. Just set this property prior to rendering your string:
g.TextRenderingHint = TextRenderingHint.SingleBitPerPixel;