用BCB 画 Code128 B模式条码
Posted Energy
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了用BCB 画 Code128 B模式条码相关的知识,希望对你有一定的参考价值。
//--------------------------------------------------------------------------- #include <vcl.h> #pragma hdrstop #include "Unit1.h" #include <string> #include <vector> #include <map> #include <Graphics.hpp> using namespace std; //--------------------------------------------------------------------------- #pragma package(smart_init) #pragma resource "*.dfm" TForm1 *Form1; //--------------------------------------------------------------------------- map<int,AnsiString> g_codemap; bool FillCodeMap(void) { if(!g_codemap.empty()) return true; g_codemap[32]="11011001100"; g_codemap[33]="11001101100"; g_codemap[34]="11001100110"; g_codemap[35]="10010011000"; g_codemap[36]="10010001100"; g_codemap[37]="10001001100"; g_codemap[38]="10011001000"; g_codemap[39]="10011000100"; g_codemap[40]="10001100100"; g_codemap[41]="11001001000"; g_codemap[42]="11001000100"; g_codemap[43]="11000100100"; g_codemap[44]="10110011100"; g_codemap[45]="10011011100"; g_codemap[46]="10011001110"; g_codemap[47]="10111001100"; g_codemap[48]="10011101100"; g_codemap[49]="10011100110"; g_codemap[50]="11001110010"; g_codemap[51]="11001011100"; g_codemap[52]="11001001110"; g_codemap[53]="11011100100"; g_codemap[54]="11001110100"; g_codemap[55]="11101101110"; g_codemap[56]="11101001100"; g_codemap[57]="11100101100"; g_codemap[58]="11100100110"; g_codemap[59]="11101100100"; g_codemap[60]="11100110100"; g_codemap[61]="11100110010"; g_codemap[62]="11011011000"; g_codemap[63]="11011000110"; g_codemap[64]="11000110110"; g_codemap[65]="10100011000"; g_codemap[66]="10001011000"; g_codemap[67]="10001000110"; g_codemap[68]="10110001000"; g_codemap[69]="10001101000"; g_codemap[70]="10001100010"; g_codemap[71]="11010001000"; g_codemap[72]="11000101000"; g_codemap[73]="11000100010"; g_codemap[74]="10110111000"; g_codemap[75]="10110001110"; g_codemap[76]="10001101110"; g_codemap[77]="10111011000"; g_codemap[78]="10111000110"; g_codemap[79]="10001110110"; g_codemap[80]="11101110110"; g_codemap[81]="11010001110"; g_codemap[82]="11000101110"; g_codemap[83]="11011101000"; g_codemap[84]="11011100010"; g_codemap[85]="11011101110"; g_codemap[86]="11101011000"; g_codemap[87]="11101000110"; g_codemap[88]="11100010110"; g_codemap[89]="11101101000"; g_codemap[90]="11101100010"; g_codemap[91]="11100011010"; g_codemap[92]="11101111010"; g_codemap[93]="11001000010"; g_codemap[94]="11110001010"; g_codemap[95]="10100110000"; g_codemap[96]="10100001100"; g_codemap[97]="10010110000"; g_codemap[98]="10010000110"; g_codemap[99]="10000101100"; g_codemap[100]="10000100110"; g_codemap[101]="10110010000"; g_codemap[102]="10110000100"; g_codemap[103]="10011010000"; g_codemap[104]="10011000010"; g_codemap[105]="10000110100"; g_codemap[106]="10000110010"; g_codemap[107]="11000010010"; g_codemap[108]="11001010000"; g_codemap[109]="11110111010"; g_codemap[110]="11000010100"; g_codemap[111]="10001111010"; g_codemap[112]="10100111100"; g_codemap[113]="10010111100"; g_codemap[114]="10010011110"; g_codemap[115]="10111100100"; g_codemap[116]="10011110100"; g_codemap[117]="10011110010"; g_codemap[118]="11110100100"; g_codemap[119]="11110010100"; g_codemap[120]="11110010010"; g_codemap[121]="11011011110"; g_codemap[122]="11011110110"; g_codemap[123]="11110110110"; g_codemap[124]="10101111000"; g_codemap[125]="10100011110"; g_codemap[126]="10001011110"; g_codemap[195]="10111101000"; g_codemap[196]="10111100010"; g_codemap[197]="11110101000"; g_codemap[198]="11110100010"; g_codemap[199]="10111011110"; g_codemap[200]="10111101110"; g_codemap[201]="11101011110"; g_codemap[202]="11110101110"; g_codemap[203]="11010000100"; g_codemap[204]="11010010000"; g_codemap[205]="11010011100"; g_codemap[206]="1100011101011"; g_codemap[207]="11011001100"; return true; } AnsiString Get128CodeString(AnsiString inputData) { int checksum = 104; char* arry = inputData.c_str(); for (int i = 0 ; i < inputData.Length() ;i++) { char a = *(arry + i); if (a + 1 >=32) { checksum += (a - 32) * (i + 1); } else { checksum += (a + 64) * (i + 1); } } checksum = checksum % 103; if (checksum < 95) { checksum += 32; } else { checksum += 100; } vector<int> nV; nV.push_back(204); for (int i = 0 ; i < inputData.Length() ;i++) { char *p = inputData.c_str() + i; nV.push_back(*p); } nV.push_back(checksum); nV.push_back(206); FillCodeMap(); AnsiString reuslt = ""; for (int i =0 ; i < nV.size() ;i++) { reuslt += g_codemap[ nV[i] ]; } return reuslt; } __fastcall TForm1::TForm1(TComponent* Owner) : TForm(Owner) { } //--------------------------------------------------------------------------- void __fastcall TForm1::Button1Click(TObject *Sender) { AnsiString text = "A012345678901234567"; text = Get128CodeString(text); Graphics::TBitmap* bitmap = new Graphics::TBitmap(); bitmap->Height = 100; int width = 2; for (int i =0 ; i < text.Length() ;i++) { bitmap->Width += width; char a = *(text.c_str() + i); bitmap->Canvas->Pen->Width = width; if (a == \'0\') { bitmap->Canvas->Pen->Color = clWhite; } else if (a == \'1\') { bitmap->Canvas->Pen->Color = clBlack; } bitmap->Canvas->MoveTo(i*width,0); bitmap->Canvas->LineTo(i*width,bitmap->Height); } bitmap->SaveToFile("1.bmp"); Image1->Picture->Bitmap->Assign(bitmap); delete bitmap; } //---------------------------------------------------------------------------
效果,可以用手机二维码扫描试试是什么内容。
参考地址:https://bbs.csdn.net/topics/350125614
以上是关于用BCB 画 Code128 B模式条码的主要内容,如果未能解决你的问题,请参考以下文章
如何做一个公式,使excel能用code128a字体生成可识别的条码
条形码 Code128Auto 是如何自动在三个子集A、B、C中切换的,或者 Code128Auto 的编码规则,请举例说明