一、使用CMake編譯x64版本qrencode
? ? ?下載地址?
GitHub - fukuchi/libqrencode: A fast and compact QR Code encoding libraryA fast and compact QR Code encoding library. Contribute to fukuchi/libqrencode development by creating an account on GitHub.https://github.com/fukuchi/libqrencode
?Configure之后會報錯,不勾選WITH_TOOLS就行了。
?
?
?文章來源地址http://www.zghlxwxcb.cn/news/detail-654992.html
?
二、UE4引入
還是采用第三方庫的形式,引入頭文件和靜態(tài)lib文件 ,注意只能在cpp里調(diào)用
#include "Runtime\Core\Public\Windows\AllowWindowsPlatformTypes.h"
#include <Windows.h>
#include "qrencode.h"
#include "Runtime\Core\Public\Windows\HideWindowsPlatformTypes.h"
?三、動態(tài)生成
以下代碼是在游戲自己創(chuàng)建的GameInstace里調(diào)用的,函數(shù)定義自己寫了
UTexture2D* UWGameInstance::CreateQRCode(FString Path,int Scale)
{
QRcode* pQRC = QRcode_encodeString(TCHAR_TO_ANSI(*Path),1,QR_ECLEVEL_L,QR_MODE_8,1);
if (!pQRC)
return nullptr;
unsigned char* QRData = pQRC->data;
UTexture2D* tex = UTexture2D::CreateTransient(pQRC->width* Scale, pQRC->width* Scale);
//
FTexture2DMipMap& mipmap = tex->PlatformData->Mips[0];
unsigned char* Data = (unsigned char*)mipmap.BulkData.Lock(LOCK_READ_WRITE);
int texturex = tex->PlatformData->SizeX;
int texturey = tex->PlatformData->SizeY;
for (int32 y = 0; y < texturey; y+= Scale)
{
for (int32 x = 0; x < texturex; x+= Scale)
{
int color = 0;
if (*QRData & 1)
{
color = 255;
}
for (int32 i = 0; i < Scale; i++)
{
for (int32 j = 0; j < Scale; j++)
{
Data[((y + i) * texturex + (x + j)) * 4 + 0] = color;//B
Data[((y + i) * texturex + (x + j)) * 4 + 1] = color;//G
Data[((y + i) * texturex + (x + j)) * 4 + 2] = color;//R
Data[((y + i) * texturex + (x + j)) * 4 + 3] = 255;//A 0:全透明;255:全不透明
}
}
//后移
QRData++;
}
}
mipmap.BulkData.Unlock();
tex->UpdateResource();
//釋放
QRcode_free(pQRC);
return tex;
}
?文章來源:http://www.zghlxwxcb.cn/news/detail-654992.html
?
到了這里,關(guān)于[UE4][C++]使用qrencode動態(tài)生成二維碼的文章就介紹完了。如果您還想了解更多內(nèi)容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!