Well, you can understand everything from this piece of code.
#include "Engine/GameViewportClient.h"
#include "HighResScreenshot.h"
----------------
FString ProjectSavedDir = FPaths::ProjectSavedDir();
FString PlacholderPath = ProjectSavedDir + "Screenshots/Screenshot.png";
FHighResScreenshotConfig& HighResScreenshotConfig = GetHighResScreenshotConfig();
HighResScreenshotConfig.SetResolution(SizeX, SizeY, SizeMultiplier);
HighResScreenshotConfig.SetFilename(PlacholderPath);
HighResScreenshotConfig.SetForce128BitRendering(bForceRendering);
HighResScreenshotConfig.SetMaskEnabled(bCustomDepthMask);
HighResScreenshotConfig.SetHDRCapture(bCaptureHDR);
ThisGameViewport->Viewport->TakeHighResScreenShot();
----------------
# May be useful
# GScreenshotResolutionX = SizeX;
# GScreenshotResolutionY = SizeY;
# GIsHighResScreenshot = false;