Created
September 30, 2020 10:20
-
-
Save Bunkerbewohner/84bd704e1cb1da17cb086aadb32cd1cd to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "QrCode.hpp" // from https://github.com/nayuki/QR-Code-generator | |
#include "ImageUtils.h" // from Unreal Engine (4.24) | |
/// <summary>Generates a QR code texture from a string.</summary> | |
/// <param name="parent">UE parent (required)</param> | |
/// <param name="string">String to encode</param> | |
UTexture2D* UWebBuzzers::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(LOCK_WRITE); | |
FMemory::Memcpy(data, pixels.GetData(), size * size * 4); | |
texture->PlatformData->Mips[0].BulkData.Unlock(); | |
texture->UpdateResource(); | |
texture->Filter = TextureFilter::TF_Nearest; | |
return texture; | |
} |
How can i implement this? I have no idea what to do with it.
@BustGame feel free to reach out here: alexandru AT outofthebox-plugins.com and I can take a look if this still works in your version of Unreal.
@BustGame feel free to reach out here: alexandru AT outofthebox-plugins.com and I can take a look if this still works in your version of Unreal.
I have no idea how can i contact you through this page but i cant implement library from nayuki into unreal engine. Tried many methods and still can't found solution. Any suggestions?
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
For everyone using a more updated version of Unreal engine, getting compilation errors on:
void* data = texture->PlatformData->Mips[0].BulkData.Lock(LOCK_WRITE);
Try using:
void* data = texture->PlatformData->Mips[0].BulkData.Lock(LOCK_READ_WRITE);
instead.