Click here to Skip to main content
15,920,633 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I want to generate barcode image with unique name and save all barcode image into specific folder.

kindly help


Thanks

What I have tried:

i Try
this work properly but replace same images

C#
string IMGFULLPATH1 = @"D:\BarCodeIMG\BCode.jpg";(---I )

 BarCodeControl barcode = new KeepAutomation.Barcode.Windows.BarCodeControl();
                                 barcode.Symbology = KeepAutomation.Barcode.Symbology.QRCode;

                                  barcode.CodeToEncode = line; //"1245718214njgjgkgfhfhnnhkjdshgjkshkgjashjkvjsdhgjkbhkjgjojoweiugfowerjgjuosdruvueijtioeueoiivgtoioewo ctjiosfjojq389594569w4245834589w48fjsdht789437985boui4wuwtr89u34689u3489t4u3tjfydgrtudrjtgwejydrhtseyd5hrjdior7tru6jhyxdgnjlkjbcfmhfhmfxcmgcjkhfhfhf57757456gffbfhfhvhukgyhm0";
                                  

                                 barcode.X = 2;
                                 barcode.Y = 2;
                                 barcode.Width = 2;
                                 barcode.AutoSize = true;
                                 barcode.Height = 2;
                                 barcode.TopMargin = 10;
                                 barcode.BottomMargin = 10;
                                 barcode.LeftMargin = 10;
                                 barcode.RightMargin = 10;
                                 barcode.DisplayText = false;                               
                                 barcode.DisplayStartStop = true;
                                 barcode.BarcodeUnit = KeepAutomation.Barcode.BarcodeUnit.Pixel;
                                 //barcode.Orientation = KeepAutomation.Barcode.Orientation.Degree90;
                                 //barcode.DPI = 72;
                                 barcode.ImageFormat = ImageFormat.Bmp;
                                 
                                 barcode.SaveAsImage(IMGFULLPATH1);
Posted
Updated 20-Apr-16 23:41pm
v3

Surely instead of hardcoding the IMGFULLPATH1, you would

a) generate a value for IMGFULLPATH1 based on the path, a 'template' for the filename - for example
pass in D:\ (path)
pass in template BCode{######}.jpg
b) use something like C# Random String Generator[^] to generate a random string of 6 Characters (that are filename legal) and replace the "######" in the 'template' with the random string
c) check that the random filename doesnt already exist ! if so go back to b
d) return the filename

the filename generator could also just use a sequential number in the place of ###### and/or have a placeholder for the date and time etc

There are also system functions to generate file names - Path.GetTempFileName for example - Im not sure how unique/what restrictions there are on using it
 
Share this answer
 
v2
I Found the solution

here
C#
string imageLocation = Server.MapPath(@"~\Images\BCode.jpg");

//The format of the image file
ImageFormat format = ImageFormat.Png;

Bitmap bmp = new Bitmap(960, 386);           //Canvas size
Graphics g = Graphics.FromImage(bmp);
Bitmap origBitmap = new Bitmap(imageLocation);
g.Clear(Color.Transparent); //Background color
// SizeF bc = g.MeasureString(codeInfo, fnt);
Brush br = new SolidBrush(Color.Black);
g.DrawImage(origBitmap, 10, 8);

BarCodeControl barcode = new KeepAutomation.Barcode.Windows.BarCodeControl();
barcode.Symbology = KeepAutomation.Barcode.Symbology.QRCode;

barcode.CodeToEncode = StripLine;


barcode.X = 2;
barcode.Y = 2;
barcode.Width = 200;
barcode.AutoSize = true;
barcode.Height = 2;
barcode.TopMargin = 10;
barcode.BottomMargin = 10;
barcode.LeftMargin = 10;
barcode.RightMargin = 10;
barcode.DisplayText = false;
barcode.DisplayStartStop = true;
barcode.BarcodeUnit = KeepAutomation.Barcode.BarcodeUnit.Pixel;
barcode.ImageFormat = ImageFormat.Bmp;

//path of unique file name
string path = string.Format("{0}{1}.png", @"D:\BarCodeIMG\", codeInfo);------------(You can here pass value from text box or other control)
barcode.SaveAsImage(path);
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900