本插件是我用源码重新封装的,不依赖静态库,纯源码,适用于多个UE版本,编辑器与打包发布都没有问题。本人在UE5EA上测试通过。
1.源码获取地址
2.插件地址
UE4UE5QRCode源码版本-互联网文档类资源-CSDN下载
3.主要修改
为了打包后可用,修改了UQRCodeComponent类的GenerateQrCode方法:
UTexture2D* UQRCodeComponent::GenerateQrCode(UObject* parent, FString string)
{
qrcodegen::QrCode qr = qrcodegen::QrCode::encodeText(TCHAR_TO_UTF8(*string), qrcodegen::QrCode::Ecc::LOW);
uint8 size = qr.getSize();
TArray<FColor> pixels;
pixels.SetNumZeroed(size * size);
FColor black = FColor::Black;
FColor white = FColor::White;
for (uint8 x = 0; x < size; x++)
{
for (uint8 y = 0; y < size; y++)
{
FColor color = qr.getModule(x, y) ? white : black;
pixels[x + y * size] = color;
}
}
UTexture2D* texture = UTexture2D::CreateTransient(size, size, EPixelFormat::PF_B8G8R8A8, "QRCode");
void* data = texture->PlatformData->Mips[0].BulkData.Lock(1);
FMemory::Memcpy(data, pixels.GetData(), size * size * 4);
texture->PlatformData->Mips[0].BulkData.Unlock();
texture->UpdateResource();
texture->Filter = TextureFilter::TF_Nearest;
return texture;
}
4.使用方法
1)创建一个actor蓝图类,为其添加QRCode组件
2)创建一个用于展示二维码的UI
3)在关卡蓝图里编写蓝图代码
4)运行效果