Last active
January 7, 2024 09:57
-
-
Save chakmeshma/ecfd61582ca31003e0fb489879bc73ac to your computer and use it in GitHub Desktop.
Unreal Screenshot Stuff
This file contains hidden or 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
| 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