条形码(barcode)code128生成代码
条形码(barcode)code128生成代码 很简单 多些这位兄弟https://bbs.csdn.net/topics/350125614
下面是我的DEMO 直接放到VS2005下面编译即可
#include <ctime>
#include <string>
#include <map>
#include <vector>
using namespace std;
#include <windows.h>
#include <atlimage.h>
map<int,string> g_codemap;
bool FillCodeMap(void);
bool GetStringCode(char *str, string &strCode);
bool GetImg(string code,CImage& img);
HDC Hdc=::GetWindowDC(::GetDesktopWindow());
int main(int argc, char **argv)
{
//"038000356216"
FillCodeMap();
string code;
GetStringCode("",code);
printf("cod:\n%s\n",code.c_str());
CImage img;
GetImg(code,img);
img.Save(L"d:/barcode-demo.jpg");//这里基本就OK了 下面是直接显示到屏幕的代码 CImage demo;
{
demo.Create(img.GetWidth()+,img.GetHeight()+,);
HBRUSH white=(HBRUSH)GetStockObject(WHITE_BRUSH);
RECT rc;
rc.left=;
rc.right=demo.GetWidth();;
rc.top=;
rc.bottom=demo.GetHeight();
HDC hdc=demo.GetDC();
::FillRect(hdc,&rc,white);
img.BitBlt(hdc,,);
demo.ReleaseDC();
} while()
{
demo.BitBlt(Hdc,,);
::Sleep();
}
return ;
} bool GetImg(string code,CImage& img)
{
if(code.empty())return false;
if(!img.IsNull())img.Destroy(); int perWid=;
int externWid=;
int hei=+externWid*;
int wid=code.length()*perWid+externWid*;
img.Create(wid,hei,);
HDC hdc=img.GetDC();
HBRUSH white=(HBRUSH)GetStockObject(WHITE_BRUSH);
HBRUSH black=(HBRUSH)GetStockObject(BLACK_BRUSH);
RECT rc;
rc.left=rc.top=;
rc.right=img.GetWidth();
rc.bottom=img.GetHeight();
::FillRect(hdc,&rc,white); rc.left=externWid;
rc.right=rc.left+perWid;
rc.top=externWid;
rc.bottom=img.GetHeight()-externWid;
const char* p=code.c_str();
for(int i=;i<code.length();++i)
{
::FillRect(hdc,&rc,p[i]==''?white:black);
rc.left+=perWid;
rc.right+=perWid;
}
img.ReleaseDC();
}
bool FillCodeMap(void)//g_codemap是个map,这我不用讲了,找个地方定义一下,在此处填充
{
if(!g_codemap.empty())
return true; g_codemap[]="";
g_codemap[]="";
g_codemap[]="";
g_codemap[]="";
g_codemap[]="";
g_codemap[]="";
g_codemap[]="";
g_codemap[]="";
g_codemap[]="";
g_codemap[]="";
g_codemap[]="";
g_codemap[]="";
g_codemap[]="";
g_codemap[]="";
g_codemap[]="";
g_codemap[]="";
g_codemap[]="";
g_codemap[]="";
g_codemap[]="";
g_codemap[]="";
g_codemap[]="";
g_codemap[]="";
g_codemap[]="";
g_codemap[]="";
g_codemap[]="";
g_codemap[]="";
g_codemap[]="";
g_codemap[]="";
g_codemap[]="";
g_codemap[]="";
g_codemap[]="";
g_codemap[]="";
g_codemap[]="";
g_codemap[]="";
g_codemap[]="";
g_codemap[]="";
g_codemap[]="";
g_codemap[]="";
g_codemap[]="";
g_codemap[]="";
g_codemap[]="";
g_codemap[]="";
g_codemap[]="";
g_codemap[]="";
g_codemap[]="";
g_codemap[]="";
g_codemap[]="";
g_codemap[]="";
g_codemap[]="";
g_codemap[]="";
g_codemap[]="";
g_codemap[]="";
g_codemap[]="";
g_codemap[]="";
g_codemap[]="";
g_codemap[]="";
g_codemap[]="";
g_codemap[]="";
g_codemap[]="";
g_codemap[]="";
g_codemap[]="";
g_codemap[]="";
g_codemap[]="";
g_codemap[]="";
g_codemap[]="";
g_codemap[]="";
g_codemap[]="";
g_codemap[]="";
g_codemap[]="";
g_codemap[]="";
g_codemap[]="";
g_codemap[]="";
g_codemap[]="";
g_codemap[]="";
g_codemap[]="";
g_codemap[]="";
g_codemap[]="";
g_codemap[]="";
g_codemap[]="";
g_codemap[]="";
g_codemap[]="";
g_codemap[]="";
g_codemap[]="";
g_codemap[]="";
g_codemap[]="";
g_codemap[]="";
g_codemap[]="";
g_codemap[]="";
g_codemap[]="";
g_codemap[]="";
g_codemap[]="";
g_codemap[]="";
g_codemap[]="";
g_codemap[]="";
g_codemap[]="";
g_codemap[]="";
g_codemap[]="";
g_codemap[]="";
g_codemap[]="";
g_codemap[]="";
g_codemap[]="";
g_codemap[]="";
g_codemap[]="";
g_codemap[]="";
g_codemap[]="";
g_codemap[]="";
g_codemap[]="";
g_codemap[]=""; return true;
}
bool GetStringCode(char *str, string &strCode)
{//传说中的code128B码就是这么造的,因为VC中的char其实就是一个int,所以对我们VC来讲更是简单无比
if(str==NULL)
return false;
if(int(strlen(str))==)
return false; vector <int> tV; int nTol = ;
int nsz = strlen(str); for (int i=;i<nsz;i++)
{
if(str[i]>=)
nTol += (str[i] - ) * (i+);
else
nTol += (str[i] + ) * (i+);
} int nEndCode = nTol%;
if (nEndCode>=)
{
if(nEndCode<=)
nEndCode = + nEndCode;
}
else
{
nEndCode += ;
} tV.push_back();//加头
for (int j=;j<nsz;j++)
tV.push_back(int(str[j]));//加内容
tV.push_back(nEndCode);//加校验码
tV.push_back();//加尾 int nV = tV.size();
for (int k=;k<nV;k++)
{
strCode += g_codemap[tV.at(k)];
} return true;
}
条形码(barcode)code128生成代码的更多相关文章
- 使用Spire.Barcode程序库生成二维码
使用Spire.Barcode程序库生成二维码 某天浏览网页发现了一个二维码的程序库.它的描述说他可以扫描二维码图像.我很感兴趣,想试试他是不是会有用.所以我就用了些方法扫描二维码图像来测试一下.结果 ...
- Android注解使用之通过annotationProcessor注解生成代码实现自己的ButterKnife框架
前言: Annotation注解在Android的开发中的使用越来越普遍,例如EventBus.ButterKnife.Dagger2等,之前使用注解的时候需要利用反射机制势必影响到运行效率及性能,直 ...
- mybatis Generator生成代码及使用方式
本文原创,转载请注明:http://www.cnblogs.com/fengzheng/p/5889312.html 为什么要有mybatis mybatis 是一个 Java 的 ORM 框架,OR ...
- x01.CodeBuilder: 生成代码框架
根据 Assembly 生成代码框架. 这是学习 AvalonEdit 的一个副产品.学习时,照着源代码新建文件夹,新建文件,添加方法与属性,虽然只是个框架,也要花费大量时间.为什么不让它自动生成呢? ...
- mybatis generator maven插件自动生成代码
如果你正为无聊Dao代码的编写感到苦恼,如果你正为怕一个单词拼错导致Dao操作失败而感到苦恼,那么就可以考虑一些Mybatis generator这个差价,它会帮我们自动生成代码,类似于Hiberna ...
- 动态生成一个设定好特殊样式的Tlabel,快速生成代码
动态生成一个设定好特殊样式的Tlabel,快速生成代码: 1.自己先在可视化界面设定一个Label,像这样: 2.选择label,快捷键ctrl+C 复制,粘贴带代码编辑器去,会生成一段这样的窗体代码 ...
- apt 根据注解,编译时生成代码
apt: @Retention后面的值,设置的为CLASS,说明就是编译时动态处理的.一般这类注解会在编译的时候,根据注解标识,动态生成一些类或者生成一些xml都可以,在运行时期,这类注解是没有的~~ ...
- 使用mybatis-generator生成代码
文档地址: http://mbg.cndocs.tk/index.html 以下是一个简单的配置内容. 一.在maven配置文件中添加mybatis-generator插件 1 2 3 4 5 ...
- WebStorm按Tab建快速生成代码模块
WS中,比如调试每次都要写的console.log(xxx);每次都要敲一遍,还有if模块,for循环模块,难道没有快捷键,可以生成代码模块吗,答案是“有”. 操作步骤如下(汉化版WS): 1.Alt ...
随机推荐
- npm 关联 git包
npm 关联 git包 由于现在项目越做越多,很多公共的部分相互公用,需要尽可能早地提炼出来,这样便可以在其他项目进行引用,而不是每次建一个项目就需要进行拷贝,这样太痛苦了,因而想通过类似npm包管理 ...
- MySQL数据库入门常用基础命令
MySQL数据库入门———常用基础命令 数据——公司的生命线,因此在大多数的互联网公司,都在使用开源的数据库产品,MySQL也因此关注度与使用率非常的高,所以做为运维的屌丝们,掌握它的一些基 ...
- 2019-11-29-Roslyn-使用-Directory.Build.props-文件定义编译
title author date CreateTime categories Roslyn 使用 Directory.Build.props 文件定义编译 lindexi 2019-11-29 08 ...
- wordpress的固定链接问题
在安装完wordpress后,按照其方法在/etc/apache2/sites-available/000-default.conf文件中添加了下述代码中的加重部分: [...] ServerAdmi ...
- 015-Zabbix自动发现和自动注册
前言 对于监控服务器越来越多的情况,如果还单独一个一个添加,那效率也太低,因此就要实现批量添加监控服务器的操作,Zabbix提供两种批量自动监控的方式: 自动发现:由服务端主动发起,Zabbix ...
- C++与C#对于引用外部文件成员使用的区别
对于C++控制台项目,如果有两个.cpp的文件都想引用同一个类的成员时,我们可以定义一个类,然后在类的头文件中添加extern来修饰. Box.cpp如下: #include "Box.h& ...
- 【mysql】全文索引match多列报错
表结构如下: CREATE TABLE `T` ( .... FULLTEXT KEY `title_fc` (`titleindex`), FULLTEXT KEY `shortname_fc` ( ...
- 对vue的solt的理解
//父 <children> <span>12345</span>//这边不会显示 </children> //子 components: { chil ...
- 上采样 及 Sub-pixel Convolution (子像素卷积)
参考:https://blog.csdn.net/leviopku/article/details/84975282 参考:https://blog.csdn.net/g11d111/article/ ...
- GO语言学习笔记3-int与byte类型转换
1.主机字节序 主机字节序模式有两种,大端数据模式和小端数据模式.在网络编程中应注意这两者的区别,以保证数据处理的正确性.例如,网络的数据是以大端数据模式进行交互,而我们的主机大多数以小端模式处理,如 ...