![]() |
Multimedia »
General Graphics »
Barcodes
Intermediate
License: The Code Project Open License (CPOL)
Drawing a Postnet barcodeBy Iven XuDrawing a Postnet barcode based on Neil Van Eps' and Rainman_63's articles |
C++, Windows, Visual Studio, MFC, Dev
|
|
Advanced Search |
|
|
|
||||||||||||||||
This article is based on Neil Van Eps' series of articles that show how to draw barcodes. In this article, the code will draw the 1D barcode of Postnet.
PostNet was developed by the United States Postal Service (USPS) to allow faster sorting and routing of mail. Postnet is the familiar, funny-looking barcode often printed on envelopes and business return mail.
This table indicates how to encode each digit of a PostNet barcode. Note that the encoding is expressed as "0" (half bar) or "1" (full bar).
| ASCII CHARACTER | BARCODE ENCODING |
| 0 | 11000 |
| 1 | 00011 |
| 2 | 00101 |
| 3 | 00110 |
| 4 | 01001 |
| 5 | 01010 |
| 6 | 01100 |
| 7 | 10001 |
| 8 | 10010 |
| 9 | 10100 |
A PostNet barcode has the following structure:
PostNet barcodes always include a modulo 10 check digit.
Before a PostNet symbol may be encoded, a checksum digit must be calculated to be subsequently appended to the end of the barcode. The checksum digit is a simple modulo 10 calculation of the sum of all the digits that are being coded.
The steps for calculating the check digit are as follows:
My CEAN13 is based on the CBarcode class, that has been introduced in Neil Van Eps' series of articles.
Here is the CPostnet class declaration. It's implemented to draw a Postnetbarcode.
class CRationalCodabar : public CBarcode
{
public:
void DrawBitmap();
void BitmapToClipboard();
CRationalCodabar();
virtual ~CRationalCodabar();
private:
CString RetrievePattern(char c);
void DrawPattern(CString csPattern);
};
void CPostnet::DrawPattern( CString csPattern )
{
int i,nXPixel,nYPixel;
CDC oDC;
// attach to the device context
oDC.Attach(m_hDC);
// initialize X pixel value
nXPixel = m_nStartingXPixel;
for (i=0;i<csPattern.GetLength();i++)
{ // X value for loop
for (nXPixel=m_nStartingXPixel;nXPixel<m_nStartingXPixel+m_nNarrowBarPixelWidth;
nXPixel++)
{
// if this is a bar
if (csPattern.GetAt(i)=='b')
{
for (nYPixel=m_nStartingYPixel;nYPixel<m_nStartingYPixel+m_nPixelHeight;nYPixel++)
{
oDC.SetPixelV(nXPixel,nYPixel,COLORBLACK);
}
}
else
{
for (nYPixel=m_nStartingYPixel;nYPixel<m_nStartingYPixel+m_nPixelHeight/2;nYPixel++)
{
oDC.SetPixelV(nXPixel,nYPixel,COLORBLACK);
}
}
for (nYPixel=m_nStartingYPixel;nYPixel<m_nStartingYPixel+m_nPixelHeight;nYPixel++)
{
oDC.SetPixelV(nXPixel+m_nNarrowBarPixelWidth,nYPixel,COLORWHITE);
}
}
// advance the starting position
m_nStartingXPixel+= 2*m_nNarrowBarPixelWidth;
}
// detach from the device context
oDC.Detach();
return;
}
Here are some resources about barcodes:
| You must Sign In to use this message board. | ||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||
General
News
Question
Answer
Joke
Rant
Admin
|
PermaLink |
Privacy |
Terms of Use
Last Updated: 8 Feb 2006 Editor: Deeksha Shenoy |
Copyright 2006 by Iven Xu Everything else Copyright © CodeProject, 1999-2009 Web20 | Advertise on the Code Project |