我有一个radgridview,我在其中使用显示数据库中的列,现在我想要打印BarCode格式。我必须首先将列值转换为位图,然后在页面上显示内容,我还想在一个页面上打印radgridview的每一行然后。
我有一个像这样的gridView,我使用字体Free 3 of 9来显示:
我希望像这样打印出来:
我必须获取Column值并将其转换为Bitmap并在页面上打印。我不知道该怎么做。如何将列值转换为图像中显示的格式,然后如何在单个页面上打印每行BarCode?
答案 0 :(得分:0)
我已经在你的另一篇文章上发布了答案,请点击此处。
How to Add the values of List<string> into the List<PictureBox> after encoding it to Barcode in c#
public Image stringToImage(string inputString)
{
string text = inputString.Trim();
Bitmap bmp = new Bitmap(1, 1);
//Set the font style of output image
Font font = new Font("Free 3 of 9", 25, FontStyle.Regular, GraphicsUnit.Pixel);
Font font2 = new Font("Arial", 15, FontStyle.Regular, GraphicsUnit.Pixel);
Graphics graphics = Graphics.FromImage(bmp);
int width = (int)graphics.MeasureString(text, font).Width;
int height = (int)graphics.MeasureString(text, font).Height;
int height2 = (int)graphics.MeasureString(text, font2).Height;
bmp = new Bitmap(bmp, new Size(width, height+height2));
graphics = Graphics.FromImage(bmp);
//Specify the background color of the image
graphics.Clear(Color.Cyan);
graphics.SmoothingMode = SmoothingMode.AntiAlias;
graphics.TextRenderingHint = TextRenderingHint.AntiAlias;
//Specify the text, font, Text Color, X position and Y position of the image
graphics.DrawString(text, font, new SolidBrush(Color.Black), 0, 0);
graphics.DrawString(text, font2, new SolidBrush(Color.Black), 0, height);
graphics.Flush();
graphics.Dispose();
//if you want to save the image uncomment the below line.
//bmp.Save(@"d:\myimage.jpg", ImageFormat.Jpeg);
return bmp;