Click here to Skip to main content
15,905,427 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
following is the code which is working and generating barcode properly but i have a problem that is i want to add text under the barcode and i was unable to get this thing please help what code should i use to get this thing possible:


private static void CreateBarcode(string codes1)
{
var myBitmap = new Bitmap(150, 50);
var g = Graphics.FromImage(myBitmap);
var jgpEncoder = GetEncoder(ImageFormat.Png);

g.Clear(Color.White);

var strFormat = new StringFormat { Alignment = StringAlignment.Center };
g.DrawString(codes1, new Font("Free 3 of 9", 21), Brushes.Black, new RectangleF(0, 0, 150, 40), strFormat);

var myEncoder = System.Drawing.Imaging.Encoder.Quality;
var myEncoderParameters = new EncoderParameters(1);

var myEncoderParameter = new EncoderParameter(myEncoder, 00L);
myEncoderParameters.Param[0] = myEncoderParameter;


//BarcodePrinter bcp = new BarcodePrinter(BarcodeData:codes1);
//bcp.Print();

myBitmap.Save(@"E:\Barcode1.png", jgpEncoder, myEncoderParameters);

}
Posted
Updated 31-Oct-13 2:16am
v2
Comments
Shubh Agrahari 31-Oct-13 8:38am    
there is some fonts for barcode just search on google u just need to install that font and in parameter u need to put "*"+YourText+"*" like this using that font ...
NairPramod 31-Oct-13 8:56am    
Sir thanks for the reply
i used code39 font and installed but as you can see i have written g.drawstring(......"Free 3 of 9") but the problem is when the barcode is generated and scanned the barcode it is fine the value of the barcode under it not shown as i know i have not wrote any code for that this is my problem.
thanks in advance

1 solution

You can use MeasureString to figure out where the text should be positioned.
http://msdn.microsoft.com/en-us/library/6xe5hazb.aspx[^]

Good luck!
 
Share this answer
 
Comments
NairPramod 1-Nov-13 0:42am    
Thanks E.F Nijboer Sir,
what should i pass in the parameter of MeasureStringMin(??????), i know i am nearby the solution.
Thanks in Advance
E.F. Nijboer 1-Nov-13 6:42am    
The method MeasureStringMin shown is just an example where they draw a rectangle and put the text in it. You would use the height and width of both barcode and text to put under it to figure out their placement.

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