条形码(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 ...
随机推荐
- JavaSE--抽象类、内部类、接口
一.抽象类 当事物不能具体描述时可将事物抽象化,只对其应有的行为进行简单的描述而不进行深度具体的描述,这样就产生了抽象类,使用abstract关键字对类进行修饰内部方法也是用abstract进行描述. ...
- npm学习(二)之如何防止权限错误
如何防止权限错误 如果您在尝试全局安装包时看到EACCES错误,请阅读本章.如果更改安装npm的目录,通常可以避免此错误.要做到这一点,要么使用版本管理器重新安装npm(推荐)或手动更改npm的默认目 ...
- node.js使用swig模块
1.安装swig npm install swig --save 2.创建app.js文件 /*应用程序入口文件*/ /*加载express模块*/ var express = require('ex ...
- mybatis中的动态代理应用(mapper对象)
-----------------UserMapper的配置信息--------------------- <?xml version="1.0" encoding=&quo ...
- idea启动,mysql连接超时错误
The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received ...
- chrome插件2
转自:http://www.codeceo.com/article/15-chrome-extension.html 1. Web Developer 支持Chrome的Web Developer扩展 ...
- PC端QQ协议说明,完美搞定QQ智能助手
一. 实验目的: 在虚拟机下NAT模式下通过Wireshark抓包,分析QQ的传输模式.了解QQ在传输信息过程中用到的协议.分析在Nat模式下,信息传输的穿透性. 二. 实验环境: Win7 专业版3 ...
- Ubuntu分区方案(菜鸟方案、常用方案和进阶方案)
菜鸟方案 “/”与swap两个分区就可以应付绝大多数的应用 常用方案 分为3个区 1. 挂载点/:主分区:安装系统和软件:大小为30G:分区格式为ext4: 2. 挂载点/home:逻辑分区:相当于“ ...
- [ERROR] Failed to execute goal org.apache.maven.plugins:maven-install-plugin:2.4:install (default-cli) on project kircp-js-plan-resource: The packaging for this project did not assign a file to the bu
结合网上的相关资料,要使用Lifecycle下的install 原因好像是Lifecycle下才会走Maven完整的phase.
- SCC统计
Kosoraju SCC总数及记录SCC所需要的最少边情况 #include<cstdio> ; ; ][N], nxt[][N], v[][N], ed, q[N], t, vis[N] ...