Skip to content

Instantly share code, notes, and snippets.

@chakmeshma
Last active January 7, 2024 09:57
Show Gist options
  • Select an option

  • Save chakmeshma/ecfd61582ca31003e0fb489879bc73ac to your computer and use it in GitHub Desktop.

Select an option

Save chakmeshma/ecfd61582ca31003e0fb489879bc73ac to your computer and use it in GitHub Desktop.
Unreal Screenshot Stuff
UTexture2D* ACustomHUD::CreateTextureFromBitmapArray(TArray<FColor>&& BitmapArray, uint16 Width, uint16& outCalculatedHeight)
{
check(BitmapArray.Num() % Width == 0);
outCalculatedHeight = BitmapArray.Num() / Width;
UTexture2D* theTexture = UTexture2D::CreateTransient(Width, outCalculatedHeight);
FTexture2DMipMap& BaseMip = theTexture->PlatformData->Mips[0];
void* mipData = BaseMip.BulkData.Lock(LOCK_READ_WRITE);
FMemory::Memcpy(mipData, BitmapArray.GetData(), BitmapArray.Num() * 4);
BaseMip.BulkData.Unlock();
theTexture->UpdateResource();
return theTexture;
}
bool ACustomPlayerController::GenerateScreenshotBitmapArray(TArray<FColor>& BitmapArray, uint16& Width, uint16& Height)
{
FViewport* currentViewport = GetWorld()->GetGameViewport()->Viewport;
if (GetViewportScreenShot(currentViewport, BitmapArray)) {
for (auto& pix : BitmapArray)
pix.A = 255;
Width = currentViewport->GetSizeXY().X;
Height = currentViewport->GetSizeXY().Y;
return true;
}
return false;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment