我面临着fontsize的尖顶条形码生成问题。当条形码的输入从5增加时,图像的大小也会增加,我需要将其调整为固定尺寸。
BarcodeSettings settings = new BarcodeSettings();
settings.Data = AccessionNo;
settings.HasBorder = false;
settings.ShowText = true;
settings.ShowTextOnBottom = true;
settings.TextAlignment = System.Drawing.StringAlignment.Center;
settings.TextColor = System.Drawing.Color.Black;
settings.Type = Spire.Barcode.BarCodeType.Code128;
settings.Code128SetMode = Code128SetMode.OnlyA;
settings.TextFont = new System.Drawing.Font("Helvetica", 8, FontStyle.Regular);
string resultString = Regex.Match(AccessionNo, @"\d+").Value;
//if(Convert.ToInt32(resultString) > 9)
//{
// settings.TextFont = new System.Drawing.Font("Helvetica", 7, FontStyle.Regular);
// settings.DpiX = 121;
//settings.DpiY = 121;
//}
//else
//{
//settings.TextFont = new System.Drawing.Font("Helvetica", 8, FontStyle.Regular);
//settings.DpiX = 140;
//settings.DpiY = 140;
//}
settings.DpiX = 121;
settings.DpiY = 121;
settings.Unit = GraphicsUnit.Millimeter;
settings.BarHeight = 6;
settings.TopMargin = 0f;
settings.LeftMargin = 0f;
settings.RightMargin = 0f;
settings.BottomMargin = 0f;
settings.ShowTopText = false;
System.Drawing.Image barcode = null;
`
答案 0 :(得分:-1)
在设置高度和宽度之前,您需要添加以下代码行: settings.AutoResize = false;
示例:
int width = 400;
int height = 200;
settings.AutoResize = false;
settings.X = 3.0f;
//Bar height
settings.BarHeight = height * 0.6f;
//Image width and height
settings.ImageWidth = width;
settings.ImageHeight = height;
//....