52 lines
1.3 KiB
C++
Executable File
52 lines
1.3 KiB
C++
Executable File
#include "DemoRenderBridge.h"
|
|
|
|
#include "Engine/TextureRenderTarget2D.h"
|
|
#include "ImageCore.h"
|
|
#include "ImageUtils.h"
|
|
|
|
bool UDemoRenderBridge::RenderTargetToPng(
|
|
UTextureRenderTarget2D* RenderTarget,
|
|
TArray<uint8>& OutPngBytes,
|
|
FString& OutError)
|
|
{
|
|
OutPngBytes.Reset();
|
|
OutError.Reset();
|
|
|
|
if (!IsInGameThread())
|
|
{
|
|
OutError = TEXT("Function must be ran on Game Thread");
|
|
return false;
|
|
}
|
|
|
|
if (!IsValid(RenderTarget))
|
|
{
|
|
OutError = TEXT("Render Target reference is invalid");
|
|
return false;
|
|
}
|
|
|
|
// Faktyczne wywolanie API C++ Unreala: odczyt Render Targetu do FImage.
|
|
FImage Image;
|
|
if (!FImageUtils::GetRenderTargetImage(RenderTarget, Image))
|
|
{
|
|
OutError = TEXT("Couldnt read Render Target");
|
|
return false;
|
|
}
|
|
|
|
// Faktyczne wywolanie API C++ Unreala: kompresja FImage do PNG w pamieci.
|
|
TArray64<uint8> Encoded;
|
|
if (!FImageUtils::CompressImage(Encoded, TEXT(".png"), Image, 0))
|
|
{
|
|
OutError = TEXT("Couldnt encode png");
|
|
return false;
|
|
}
|
|
|
|
if (Encoded.Num() > MAX_int32)
|
|
{
|
|
OutError = TEXT("Result too large");
|
|
return false;
|
|
}
|
|
|
|
OutPngBytes.Append(Encoded.GetData(), static_cast<int32>(Encoded.Num()));
|
|
return true;
|
|
}
|