Here is some sample code that seems to work for my project:
std::string fpath = "C:\UnrealEngineProjects\SampleProject\SampleImage.png"
FString filePath(fpath.c_str());
GIsHighResScreenshot = true;
GetHighResScreenshotConfig().ResolutionMultiplier = 6; //Sets the res multiplier
UGameViewportClient* ViewportClient = GetWorld()->GetGameViewport();
ViewportClient->OnScreenshotCaptured().Clear();
//can't use filePath as a function parameter, therefore need to 'capture' it (Capturing an object by name makes a lambda-local copy of the object.)
ViewportClient->OnScreenshotCaptured().AddLambda(
[filePath](int32 SizeX, int32 SizeY, const TArray<FColor>& Bitmap)
{
// Make sure that all alpha values are opaque.
TArray<FColor>& RefBitmap = const_cast<TArray<FColor>&>(Bitmap);
for (auto& Color : RefBitmap)
Color.A = 255;
TArray<uint8> CompressedBitmap;
FImageUtils::CompressImageArray(SizeX, SizeY, RefBitmap, CompressedBitmap);
//FString ScreenshotFilePath = GetScreenshotFilePath(CleanSlotFileName);
FFileHelper::SaveArrayToFile(CompressedBitmap, *filePath);
});
GEngine->AddOnScreenDebugMessage(-1, 15.0f, FColor::Yellow, TEXT("Saving a high res screenshot at location " + fpath));
FScreenshotRequest::RequestScreenshot(filePath, false);
GetWorld()->GetGameViewport()->Viewport->TakeHighResScreenShot();