A. 如何用c語言實現顯示二維碼
下一個easyx圖形函數庫吧,自動安裝的,帶chm函數說明。
B. 求二維碼的生成演算法 C語言
二維碼有很多種標准,可以控制存儲數據的信息量,也可以控制容錯的數據量[使得部分污損的二維碼可以被正常讀取]
通常的做法是調用二維碼設計方提供的組件,像你這個准備自己生成二維碼,應該可以生成可以看起來很像的東西。
但是估計其餘的讀碼工具都讀取不出來。
C. c#實現二維碼編碼過程
C# 生成二維碼
在C#中直接引用ThoughtWorks.QRCode.dll 類,
ThoughtWorks.QRCode.Codec.QRCodeEncoder encoder = new QRCodeEncoder();
encoder.QRCodeEncodeMode = QRCodeEncoder.ENCODE_MODE.BYTE;//編碼方式(注意:BYTE能支持中文,ALPHA_NUMERIC掃描出來的都是數字)
encoder.QRCodeScale = 4;//大小(值越大生成的二維碼圖片像素越高)
encoder.QRCodeVersion = 0;//版本(注意:設置為0主要是防止編碼的字元串太長時發生錯誤)
encoder.QRCodeErrorCorrect = QRCodeEncoder.ERROR_CORRECTION.M;//錯誤效驗、錯誤更正(有4個等級)
String qrdata = "二維碼信息";
System.Drawing.Bitmap bp = encoder.Encode(qrdata.ToString(), Encoding.GetEncoding("GB2312"));
Image image = bp;
pictureBox1.Image = bp;
保存二維碼圖片:
SaveFileDialog sf = new SaveFileDialog();
sf.Title = "選擇保存文件位置";
sf.Filter = "保存圖片(*.jpg) |*.jpg|所有文件(*.*) |*.*";
//設置默認文件類型顯示順序
sf.FilterIndex = 1;
//保存對話框是否記憶上次打開的目錄
sf.RestoreDirectory = true;
if (sf.ShowDialog() == DialogResult.OK)
{
Image im = this.pictureBox1.Image;
//獲得文件路徑
string localFilePath = sf.FileName.ToString();
if (sf.FileName != "")
{
string fileNameExt = localFilePath.Substring(localFilePath.LastIndexOf("\\") + 1);//獲取文件名,不帶路徑
// newFileName = fileNameExt+DateTime.Now.ToString("yyyyMMdd") ;//給文件名後加上時間
string FilePath = localFilePath.Substring(0, localFilePath.LastIndexOf(".")); //獲取文件路徑,帶文件名,不帶後綴
string fn = sf.FileName;
pictureBox1.Image.Save(FilePath +"-"+ DateTime.Now.ToString("yyyyMMdd") + ".jpg");
}
}
//解析二維碼信息
// QRCodeDecoder decoder = new QRCodeDecoder();
// String decodedString = decoder.decode(new QRCodeBitmapImage(new Bitmap(pictureBox1.Image)));
//this.label3.Text = decodedString;
2、另一種方法,引用ZXing類庫。
ZXing是一個開源Java類庫用於解析多種格式的1D/2D條形碼。目標是能夠對QR編碼、Data Matrix、UPC的1D條形碼進行解碼。於此同時,它同樣提供 cpp,ActionScript,android,iPhone,rim,j2me,j2se,jruby,C#等方式的類庫。zxing類庫的作用主 要是解碼,是目前開源類庫中解碼能力比較強的(商業的另說,不過對於動輒成千上萬的類庫授權費用,的確很值)。
到谷歌code下載相應的代碼
1.下載zxing最新的包
到zxing的主頁: http://code.google.com/p/zxing/
找到其中的CSharp文件夾,在vs中打開並編譯,將obj下debug中的zxing.dll復制並粘帖到你的項目中的bin文件目錄下,
右擊添加項目引用。將zxing.dll引用到項目中,就可以在需要的地方使用了。
源代碼中有兩處UTF-8的問題,會導致中文出現亂碼(編譯.dll之前修改)
其一:com.google.zxing.qrcode.encoder.encoder類中的
internal const System.String DEFAULT_BYTE_MODE_ENCODING = "ISO-8859-1";
此處,將ISO-8859-1改為UTF-8
其二:com.google.zxing.qrcode.decoder.DecodedBitStreamParser類的成員
private const System.String UTF8 = "UTF8";
應將UTF8改為UTF-8
生成代碼:
//引用
using com.google.zxing.qrcode;
using com.google.zxing;
using com.google.zxing.common;
using ByteMatrix = com.google.zxing.common.ByteMatrix;
using EAN13Writer = com.google.zxing.oned.EAN13Writer;
using EAN8Writer = com.google.zxing.oned.EAN8Writer;
using MultiFormatWriter = com.google.zxing.MultiFormatWriter;
方法:
string content = "二維碼信息";
ByteMatrix byteMatrix = new MultiFormatWriter().encode(content, BarcodeFormat.QR_CODE, 300, 300);
Bitmap bitmap = toBitmap(byteMatrix);
pictureBox1.Image = bitmap;
SaveFileDialog sFD = new SaveFileDialog();
sFD.Filter = "保存圖片(*.png) |*.png|所有文件(*.*) |*.*";
sFD.DefaultExt = "*.png|*.png";
sFD.AddExtension = true;
if (sFD.ShowDialog() == DialogResult.OK)
{
if (sFD.FileName != "")
{
writeToFile(byteMatrix, System.Drawing.Imaging.ImageFormat.Png, sFD.FileName);
}
}
解析:
if (this.openFileDialog1.ShowDialog() != DialogResult.OK)
{
return;
}
Image img = Image.FromFile(this.openFileDialog1.FileName);
Bitmap bmap;
try
{
bmap = new Bitmap(img);
}
catch (System.IO.IOException ioe)
{
MessageBox.Show(ioe.ToString());
return;
}
if (bmap == null)
{
MessageBox.Show("Could not decode image");
return;
}
LuminanceSource source = new RGBLuminanceSource(bmap, bmap.Width, bmap.Height);
com.google.zxing.BinaryBitmap bitmap1 = new com.google.zxing.BinaryBitmap(new HybridBinarizer(source));
Result result;
try
{
result = new MultiFormatReader().decode(bitmap1);
}
catch (ReaderException re)
{
MessageBox.Show(re.ToString());
return;
}
MessageBox.Show(result.Text);
public static void writeToFile(ByteMatrix matrix, System.Drawing.Imaging.ImageFormat format, string file)
{
Bitmap bmap = toBitmap(matrix);
bmap.Save(file, format);
}
public static Bitmap toBitmap(ByteMatrix matrix)
{
int width = matrix.Width;
int height = matrix.Height;
Bitmap bmap = new Bitmap(width, height, System.Drawing.Imaging.PixelFormat.Format32bppArgb);
for (int x = 0; x < width; x++)
{
for (int y = 0; y < height; y++)
{
bmap.SetPixel(x, y, matrix.get_Renamed(x, y) != -1 ? ColorTranslator.FromHtml("0xFF000000") : ColorTranslator.FromHtml("0xFFFFFFFF"));
}
}
return bmap;
}
D. 誰有C語言或C++編寫的二維碼解碼軟體的源程序
這個程序是運行在什麼平台的?
二維碼的輸入來自攝像頭還是來自圖片?
目前來看,網上有一些開源的跨平台的開發包,需要安裝相應的庫才能使用。不可能像你想像的那麼簡單給你發個源代碼你就立刻能用了。
比較實用的一個開發包是Zbar,開源不收費。親測在Win7,WinXP環境下可以成功編譯運行。
http://zbar.sourceforge.net
去這里下載他的SDK,裡面有相應的常式,根據你的具體運行環境和具體的需要來修改吧。
祝你好運
E. 想要c語言生成qr碼的源代碼(拜託)
int strcpy(char *s1,const char *s2);
開辟一個緩沖區,比如
char buff[100];//假設你的字元串不超過這么多
而你的而為數組為
char **argv;
其中argv[0] = "this is the first string";
argv[1] = "this is the seconde string";
你只須調用如下
strcpy(buff,argv[0]);
strcpy(argv[0],argv[1]);
strcpy(argv[1],buff);
一下是完整代碼,並測試過
#include <stdio.h>
#include <string.h>
char argv[2][100]=;
// 存儲字元串的二維數組,每個字元串最長為99個位元組
char buff[100];
//緩沖區
int main()
{
printf("轉換前:\n");
printf("argv[0] = %s\n",argv[0]);
printf("argv[1] = %s\n",argv[1]);
strcpy(buff,argv[0]);
strcpy(argv[0],argv[1]);
strcpy(argv[1],buff);
printf("轉換後:\n");
printf("argv[0] = %s\n",argv[0]);
printf("argv[1] = %s\n",argv[1]);
return 0;
}
vae.la
F. 如何用C語言實現顯示二維碼
intFb_QrDisp(intiPenX,intiPenY,QRcode*pQRcode)
{
T_PixelDatasg_tOriginPixelDatas;
T_PixelDatasg_tZoomPixelDatas;
//intiZoom;
inti;
g_tOriginPixelDatas.iWidth=pQRcode->width;
g_tOriginPixelDatas.iHeight=pQRcode->width;
g_tOriginPixelDatas.iLineBytes=g_tOriginPixelDatas.iWidth;
g_tOriginPixelDatas.aucPixelDatas=pQRcode->data;
/*
if(pQRcode->version<=1)
{
iZoom=2;
}
else
{
iZoom=2;
}
g_tZoomPixelDatas.iWidth=pQRcode->width*iZoom;
g_tZoomPixelDatas.iHeight=pQRcode->width*iZoom;
g_tZoomPixelDatas.iLineBytes=g_tZoomPixelDatas.iWidth;
g_tZoomPixelDatas.aucPixelDatas=malloc(g_tZoomPixelDatas.iWidth*
g_tZoomPixelDatas.iHeight);
if(g_tZoomPixelDatas.aucPixelDatas==NULL)
{
printf("g_tZoomPixelDatas->aucPixelDatasmallocfailed ");
return-1;
}
PicZoom(&g_tOriginPixelDatas,&g_tZoomPixelDatas);
#if0
printf("g_tZoomPixelDatas.iWidth=%d,g_tZoomPixelDatas.iHeight=%d ",
g_tZoomPixelDatas.iWidth,g_tZoomPixelDatas.iHeight);
for(i=0;i<(g_tZoomPixelDatas.iWidth*g_tZoomPixelDatas.iHeight);i++)
{
printf("0x%x,",g_tZoomPixelDatas.aucPixelDatas[i]);
}
printf(" ");
#endif
*/
Disp_FixelPic(iPenX,iPenY,&g_tZoomPixelDatas);
return0;
}
需要使用Qrcode
G. qrcode生成二維碼 鏈接怎麼做
1、首先在頁面中加入jquery庫文件和qrcode插件。
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="jquery.qrcode.min.js"></script>
2、在頁面中需要顯示二維碼的地方加入以下代碼:
<div id="code"></div>
3、調用qrcode插件。
qrcode支持canvas和table兩種方式進行圖片渲染,默認使用canvas方式,效率最高,當然要瀏覽器支持html5。直接調用如下:
$('#code').qrcode("http://www.helloweba.com"); //任意字元串
您也可以通過以下方式調用:
$("#code").qrcode({
render: "table", //table方式
width: 200, //寬度
height:200, //高度
text: "www.helloweba.com" //任意內容
});
這樣就可以在頁面中直接生成一個二維碼,你可以用手機「掃一掃」功能讀取二維碼信息。
識別中文
我們試驗的時候發現不能識別中文內容的二維碼,通過查找多方資料了解到,jquery-qrcode是採用charCodeAt()方式進行編碼轉換的。而這個方法默認會獲取它的Unicode編碼,如果有中文內容,在生成二維碼前就要把字元串轉換成UTF-8,然後再生成二維碼。您可以通過以下函數來轉換中文字元串:
function toUtf8(str) {
var out, i, len, c;
out = "";
len = str.length;
for(i = 0; i < len; i++) {
c = str.charCodeAt(i);
if ((c >= 0x0001) && (c <= 0x007F)) {
out += str.charAt(i);
} else if (c > 0x07FF) {
out += String.fromCharCode(0xE0 | ((c >> 12) & 0x0F));
out += String.fromCharCode(0x80 | ((c >> 6) & 0x3F));
out += String.fromCharCode(0x80 | ((c >> 0) & 0x3F));
} else {
out += String.fromCharCode(0xC0 | ((c >> 6) & 0x1F));
out += String.fromCharCode(0x80 | ((c >> 0) & 0x3F));
}
}
return out;
}
以下示例:
var str = toUtf8("釣魚島是中國的!");
$('#code').qrcode(str);
H. qrcode 生成二維碼多少種方式
好多種方式:
從是否需要上網,可以分為在線和離線。
從調用語言分,可分為c,c++,java,php等。
如果要這么說,總共有大概百多種吧。
我們是把生成部分編譯成了一個伺服器軟體,通過http調用。就沒有語言的區別了。
I. 有誰知道QRcode生成二維碼時,把想要的數據換行。
網路半天未果,突發奇想,利用多行文本框居然成功了。希望能給更多的朋友帶來幫助!
直接上代碼(VB6+QRmaker):
Me.Text1.Text = "批次:1408M1" & Chr(10) & "圖號:M01-01-001"
Me.QRmaker1.InputData = Me.Text1.Text '讀取支持換行的文本框
Me.QRmaker1.Refresh
Picture1.Picture = Me.QRmaker1.Picture
SavePicture Picture1.Image, App.Path & "二維碼.bmp" '生成二維碼圖片
生成的圖片:
手機掃描結果:
批次:1408M1
圖號:M01-01-001
J. C語言或C++編寫二維碼的解碼部分詳細的源代碼及說明
1、二維碼有很多種標准,可以控制存儲數據的信息量,也可以控制容錯的數據量[使得部分污損的二維碼可以被正常讀取。通常的做法是調用二維碼設計方提供的組件,如果是自己生成二維碼,應該可以生成可以看起來很像的東西。
2、常式:
<pre name="code" class="cpp">int Fb_QrDisp(int iPenX,int iPenY,QRcode*pQRcode)
{
T_PixelDatasg_tOriginPixelDatas;
T_PixelDatasg_tZoomPixelDatas;
//intiZoom;
inti;
g_tOriginPixelDatas.iWidth= pQRcode->width;
g_tOriginPixelDatas.iHeight=pQRcode->width;
g_tOriginPixelDatas.iLineBytes=g_tOriginPixelDatas.iWidth;
g_tOriginPixelDatas.aucPixelDatas= pQRcode->data;
/*
if(pQRcode->version< = 1)
{
iZoom= 2;
}
else
{
iZoom= 2;
}
g_tZoomPixelDatas.iWidth = pQRcode->width*iZoom;
g_tZoomPixelDatas.iHeight=pQRcode->width*iZoom;
g_tZoomPixelDatas.iLineBytes=g_tZoomPixelDatas.iWidth;
g_tZoomPixelDatas.aucPixelDatas= malloc(g_tZoomPixelDatas.iWidth* g_tZoomPixelDatas.iHeight);
if(g_tZoomPixelDatas.aucPixelDatas== NULL)
{
printf("g_tZoomPixelDatas->aucPixelDatasmalloc failed ");
return-1;
}
PicZoom(&g_tOriginPixelDatas,&g_tZoomPixelDatas);
#if 0
printf("g_tZoomPixelDatas.iWidth=%d,g_tZoomPixelDatas.iHeight=%d ", g_tZoomPixelDatas.iWidth,g_tZoomPixelDatas.iHeight);
for(i=0;i<(g_tZoomPixelDatas.iWidth*g_tZoomPixelDatas.iHeight);i++)
{
printf("0x%x,",g_tZoomPixelDatas.aucPixelDatas[i]);
}
printf(" ");
#endif
*/
Disp_FixelPic(iPenX,iPenY,&g_tZoomPixelDatas);
return 0;
}
因為stmf429運行起來後內存不夠,這里不用申請內存再擴充放大二維碼數據的方法,而是直接描點。所以這里注釋掉了放大部分。