I am using Leadtools Image Pro 17 with VS 2010.
I'm using the SpecialEffects.DrawRotated3DText to render 2D text with rotation (style Normal) to both the screen (Using the RasterImageViewer's graphics object (e.CreateGraphics()) and the printer's graphic object from the standard .NET printer objects.
I have a truetype barcode font which appears to display correctly on the screen, but appears to be getting smudged in some areas when it prints. Divisions which are visible between the black lines of barcode on the screen coerce into black blocks on the printer in some cases. This results in a barcode that is unusable.
It 'feels' to me like a resolution or DPI mis-match between the DrawRotated3DText and the e.Graphics context it is rendering to.
The printer uses media that is 3.375" x 2.145", and reports as 300DPI for both directions when I look at the information returned by the PageSettings object.
Printing the same data to a standard 8 1/2" x 11" sheet of paper results in both excellent text and barcodes. However, this is likely due to the fact that the fonts are proportionally increased in size so that they are in the same relative location, and occupy the same relative space they would if printed on the smaller page.
I create a Leadtools RasterImage which has the same properties as the printer's printing area:
DPIx and DPIy are both 300 in this case.
w & h are the size in pixels reported by the printer of the media.
RasterDefaults.XResolution = DPIx;
RasterDefaults.YResolution = DPIy;
LEAD1.Image = new RasterImage(RasterMemoryFlags.Conventional, w, h, 24, RasterByteOrder.Rgb, RasterViewPerspective.TopLeft, null, System.IntPtr.Zero,0);
badgeSideBitmap = new Bitmap(RasterImageConverter.ConvertToImage(LEAD1.Image, ConvertToImageOptions.None));
badgeSideBitmap.SetResolution((float)DPIx, (float)DPIy);
Graphics g = Graphics.FromImage(badgeSideBitmap);
g.Clear(Color.White);
LEAD1.Image = RasterImageConverter.ConvertFromImage(badgeSideBitmap, ConvertFromImageOptions.None);
g.Dispose();
I think I had to go through the bitmap -> rasterimage logic so I could clear the image to white initially. If there's a cleaner way to do this, I'd appreciate the tip.
I grab the image from the RasterImageviewer, because I want to use standard GDI+ methods to draw on it
RasterImageGdiPlusGraphicsContainer ric = new RasterImageGdiPlusGraphicsContainer(LEAD1.Image);
Graphics g = ric.Graphics;
Maybe, I shouldn't use a smoothing mode for text?
g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
This call, results in lousy barcodes. Normal text print just fine.
Rotation is 0, Style is Normal, alignment is normally center/center.
All the color values are set to black.
fntDraw renders at 18 points. I am using the free Elfring 39 (3 of 9) fonts for the barcodes.
_processor.DrawRotated3dText(
g,
_textOptions.Text,
new Rectangle((int)this.Left, (int)this.Top, (int)this.Width, (int)this.Height),
(int)this.Rotation * 10,
_textOptions.Style,
_textOptions.Alignment,
0,
0,
_textOptions.TextColor,
_textOptions.TextColor,
_textOptions.TextColor,
fntDraw,null);
This results in better barcodes, but lousy text:
Rectangle txtRect = new Rectangle((int)this.Left, (int)this.Top, (int)this.Width, (int)this.Height);
g.TextRenderingHint = TextRenderingHint.SingleBitPerPixel;
if (this.Rotation != 0)
{
g.TranslateTransform(txtRect.X + txtRect.Width / 2, txtRect.Y + txtRect.Height / 2); // we define the center of rotation in the center of the container rectangle
g.RotateTransform((float)this.Rotation); // this doesn't change
var newRectangle = new Rectangle(-txtRect.Height / 2, -txtRect.Width / 2, txtRect.Height, txtRect.Width); // notice that width is switched with height
g.DrawString(_textOptions.Text, fntDraw, new SolidBrush(Color.Black), newRectangle, new StringFormat
{
LineAlignment = StringAlignment.Near,
Alignment = StringAlignment.Near,
Trimming = StringTrimming.None
});
g.ResetTransform();
}
else
{
g.DrawString(_textOptions.Text, fntDraw, new SolidBrush(Color.Black), txtRect, new StringFormat
{
LineAlignment = StringAlignment.Center,
Alignment = StringAlignment.Center,
Trimming = StringTrimming.None
});
}
Both font and barcode look good if I use the exact same fonts in Wordpad.
What am I missing?