How to save a high res screenshot from code?

Hey guys, so I’m trying to set up a system that allows users to save a high res screenshot (Basically a render) to a custom location. I’ve got the save dialog working, so I can get a custom path, but how would I go about grabbing a high resolution screenshot and saving it to that path? I found FViewport->TakeHighResScreenshot(), but it doesn’t let me define resolution or save location.

Any ideas?

Hey, have a look at FScreenshotRequest in Engine\Source\Runtime\Engine\Public\UnrealClient.h:

/**
 * Requests a new screenshot with a specific filename
 *
 * @param InFilename	The filename to use
 * @param bInShowUI		Whether or not to show Slate UI
 */
static void RequestScreenshot( const FString& InFilename, bool bInShowUI );

Hmm, I’m trying to use that but it doesn’t seem to do anything, this is my code:

TArray<FString> selectedFiles;
bool test = FDesktopPlatformModule::Get()->SaveFileDialog(GetDesktopWindow(), "Save a screenshot:", "C:\\", ".bmp", "Bitmap Image|.bmp", EFileDialogFlags::None, selectedFiles);
	
GIsHighResScreenshot = true;
GScreenshotResolutionX = 3000;
GScreenshotResolutionY = 2000;

FScreenshotRequest::RequestScreenshot(selectedFiles[0], true);

As far as I can tell the SaveFileDialog is spitting out a legitimate path (…/…/…/…/…/…/Test/test.bmp), but no files are being written.

Also, I’m guessing the GScreenshotResolution stuff is how you make it higher res, but I’m not sure.

Using this should work:

GEngine->AddOnScreenDebugMessage(-1, 5.0f, FColor::Yellow, TEXT("Requesting screenshot")); // display message on window (to check that you are actually calling the lines below)
FString fileName("C:/path/to/folder/screenshot.png");
FScreenshotRequest::RequestScreenshot(fileName, false, false);

Make sure you add:

#include "Engine.h"

at the top of your class.

Thanks for the help. I’ve been trying to figure this one out on and off for a few months now.

it always saves screenshot in Saved\Screenshots\Windows and does not follow file name…