Hi,
I used this code.
GetWorld()->GetGameViewport()->OnScreenshotCaptured().AddUObject(this, &AScreenShotMgr::OnScreenshotComplete);
void AScreenShotMgr::OnScreenshotComplete(int32 sizeX, int32 sizeY, const TArray<FColor>& Bitmap)
{
GetWorld()->GetGameViewport()->OnScreenshotCaptured().Remove(callbackHandle);
FIntPoint DestSize(sizeX, sizeY);
FString FileFullPath = screenshotDirectory + GetFilename() + ".png";
TArray<uint8> CompressedBitmap;
FImageUtils::CompressImageArray(DestSize.X, DestSize.Y, Bitmap, CompressedBitmap);
const bool bTree = true;
IFileManager::Get().MakeDirectory(*FPaths::GetPath(screenshotDirectory), bTree);
FFileHelper::SaveArrayToFile(CompressedBitmap, *FileFullPath);
}