I make take screenshot. But it is only works on editor.
This is my Take Screenshot smaple code.
UGameViewportClient* GameViewport = GWorld->GetGameViewport();
FViewport* Viewport = GameViewport->Viewport;
Viewport->Draw();
FReadSurfaceDataFlags ReadPixelFlags(RCM_MinMaxNorm);
ReadPixelFlags.SetLinearToGamma(true);
// Read the contents of the viewport into an array.
TArray<FColor> Bitmap;
if (Viewport->ReadPixels(Bitmap, ReadPixelFlags))
{
check(Bitmap.Num() == Viewport->GetSizeXY().X * Viewport->GetSizeXY().Y);
// Initialize alpha channel of bitmap
for (auto& Pixel : Bitmap)
{
Pixel.A = 255;
}
}
// Create screenshot folder if not already present.
if (IFileManager::Get().MakeDirectory(*FPaths::ScreenShotDir(), true))
{
// Save the contents of the array to a bitmap file.
FHighResScreenshotConfig& HighResScreenshotConfig = GetHighResScreenshotConfig();
HighResScreenshotConfig.bDumpBufferVisualizationTargets = true;
HighResScreenshotConfig.SetHDRCapture(true);
FString ScreenshotSaveName;
FFileHelper::GenerateNextBitmapFilename(_fileDirectory / _fileName, TEXT("png"), ScreenshotSaveName);
HighResScreenshotConfig.SaveImage(ScreenshotSaveName, Bitmap, GameViewport->Viewport->GetSizeXY());
}
I got a good image from the editor, but not from Standalong. It only output black images. (Inserted alpha value.)
This is Result Image
What is problem?