使用 code128.BarHeight 时在条形码下方显示文本
Display text underneath barcode when using code128.BarHeight
我正在尝试在条形码下方显示文本,但到目前为止没有成功。
这是我目前尝试过的;
Bitmap bmpButton = new Bitmap(206, 38);
Bitmap bmpBackground = new Bitmap(CreateBarcode("AA12334566"));
// We use the default image as a background brush
TextureBrush objBrush = new TextureBrush(bmpBackground);
Graphics objGraphics;
objGraphics = Graphics.FromImage(bmpButton);
// objGraphics.TextRenderingHint = Drawing.Text.TextRenderingHint.AntiAlias
// We draw the background image...
objGraphics.FillRectangle(objBrush, 0, 0, 206, 38);
objGraphics.DrawString("AA1234567", new System.Drawing.Font("Arial", 8, FontStyle.Regular), SystemBrushes.WindowText, new Point(0, 14));
Response.ContentType = "image/jpeg";
bmpButton.Save(Response.OutputStream, ImageFormat.Jpeg);
private System.Drawing.Image CreateBarcode(string data)
{
Barcode128 code128 = new Barcode128();
code128.Code = data;
System.Drawing.Image barCode = code128.CreateDrawingImage(System.Drawing.Color.Black, System.Drawing.Color.White);
return barCode;
}
代码
private void Form1_Load(object sender, EventArgs e)
{
Bitmap bmpButton = new Bitmap(206, 48);
Graphics graphics = Graphics.FromImage(bmpButton);
graphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
graphics.PixelOffsetMode = System.Drawing.Drawing2D.PixelOffsetMode.HighQuality;
graphics.CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.HighQuality;
graphics.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;
graphics.FillRectangle(Brushes.White, new Rectangle(0, 0, 206, 48));
graphics.DrawImage(CreateBarcode("AA12334566"), 5, 5);
graphics.DrawString("AA12334566",new Font(FontFamily.GenericSansSerif, 12), Brushes.Black, new RectangleF(0, 28, 206, 20));
graphics.Save();
bmpButton.Save(@"D:3.jpeg", ImageFormat.Jpeg);
}
private System.Drawing.Image CreateBarcode(string data)
{
Barcode128 code128 = new Barcode128();
code128.Code = data;
System.Drawing.Image barCode = code128.CreateDrawingImage(System.Drawing.Color.Black, System.Drawing.Color.White);
return barCode;
}
结果图片
并且请不要拉伸条形码图像,因为它会导致错误的转换
////// 旧答案 /////
objGraphics.DrawString("AA1234567", new System.Drawing.Font("Arial", 8, FontStyle.Regular), SystemBrushes.WindowText, new Point(0, 14));
in above line at the end [new Point(0, 14)] 指定文本的位置为 x-axis 和 y-axis 并且如果你想要降低文本的位置你可以增加 y 而不是 14 使用 28
我正在尝试在条形码下方显示文本,但到目前为止没有成功。
这是我目前尝试过的;
Bitmap bmpButton = new Bitmap(206, 38);
Bitmap bmpBackground = new Bitmap(CreateBarcode("AA12334566"));
// We use the default image as a background brush
TextureBrush objBrush = new TextureBrush(bmpBackground);
Graphics objGraphics;
objGraphics = Graphics.FromImage(bmpButton);
// objGraphics.TextRenderingHint = Drawing.Text.TextRenderingHint.AntiAlias
// We draw the background image...
objGraphics.FillRectangle(objBrush, 0, 0, 206, 38);
objGraphics.DrawString("AA1234567", new System.Drawing.Font("Arial", 8, FontStyle.Regular), SystemBrushes.WindowText, new Point(0, 14));
Response.ContentType = "image/jpeg";
bmpButton.Save(Response.OutputStream, ImageFormat.Jpeg);
private System.Drawing.Image CreateBarcode(string data)
{
Barcode128 code128 = new Barcode128();
code128.Code = data;
System.Drawing.Image barCode = code128.CreateDrawingImage(System.Drawing.Color.Black, System.Drawing.Color.White);
return barCode;
}
代码
private void Form1_Load(object sender, EventArgs e)
{
Bitmap bmpButton = new Bitmap(206, 48);
Graphics graphics = Graphics.FromImage(bmpButton);
graphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
graphics.PixelOffsetMode = System.Drawing.Drawing2D.PixelOffsetMode.HighQuality;
graphics.CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.HighQuality;
graphics.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;
graphics.FillRectangle(Brushes.White, new Rectangle(0, 0, 206, 48));
graphics.DrawImage(CreateBarcode("AA12334566"), 5, 5);
graphics.DrawString("AA12334566",new Font(FontFamily.GenericSansSerif, 12), Brushes.Black, new RectangleF(0, 28, 206, 20));
graphics.Save();
bmpButton.Save(@"D:3.jpeg", ImageFormat.Jpeg);
}
private System.Drawing.Image CreateBarcode(string data)
{
Barcode128 code128 = new Barcode128();
code128.Code = data;
System.Drawing.Image barCode = code128.CreateDrawingImage(System.Drawing.Color.Black, System.Drawing.Color.White);
return barCode;
}
结果图片
并且请不要拉伸条形码图像,因为它会导致错误的转换
////// 旧答案 /////
objGraphics.DrawString("AA1234567", new System.Drawing.Font("Arial", 8, FontStyle.Regular), SystemBrushes.WindowText, new Point(0, 14));
in above line at the end [new Point(0, 14)] 指定文本的位置为 x-axis 和 y-axis 并且如果你想要降低文本的位置你可以增加 y 而不是 14 使用 28