# How to set the file target for a high res screenshot

**URL:** <https://forums.unrealengine.com/t/how-to-set-the-file-target-for-a-high-res-screenshot/312470>\
**Category:** Programming & Scripting\
**Tags:** unreal-engine\
**Created:** [March 25, 2015, 1:13am UTC](https://forums.unrealengine.com/t/how-to-set-the-file-target-for-a-high-res-screenshot/312470 "2015-03-25T01:13:08Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![anonymous\_user\_d44e7f33](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_d44e7f33](https://forums.unrealengine.com/u/anonymous_user_d44e7f33)\
**Post date:** [March 25, 2015, 1:13am UTC](https://forums.unrealengine.com/t/how-to-set-the-file-target-for-a-high-res-screenshot/312470/1 "2015-03-25T01:13:08Z")

</div>

Hey Guys,

I’m trying to save a high resolution screenshot to a user-specified file path (Something I’ve tried a number of times before). I can save a regular screenshot to a location, and I can save a high-res screenshot to the default Screenshot directory, but I can’t seem to do both at once.

Here’s my code at the moment:

```
FScreenshotRequest::RequestScreenshot(filePath, false); //Sets my custom file path
GetHighResScreenshotConfig().ResolutionMultiplier = 4; //Sets the res multiplier
GetWorld()->GetGameViewport()->Viewport->TakeHighResScreenShot(); //Sets the flag in the viewport to take the high-res shot.

```

As far as I can tell, it’s because FViewport::TakeHighResScreenShot() just sets a flag that tells the Draw function to then call the FViewport::HighResScreenshot(), but that means it always calls:

```
 `FScreenshotRequest::RequestScreenshot( bShowUI, TEXT("png") );`

```

Which resets the file path I set up previously. Is there any way around this? Is there a reason HighResScreenshot() is protected? Is there a way I can change the default Screenshot directory on the fly?

---

<div class="post-metadata">

**Author:** ![kaitorched](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@kaitorched](https://forums.unrealengine.com/u/kaitorched)\
**Post date:** [June 9, 2016, 4:40pm UTC](https://forums.unrealengine.com/t/how-to-set-the-file-target-for-a-high-res-screenshot/312470/2 "2016-06-09T16:40:56Z")

</div>

Did you find a solution for this?

---

<div class="post-metadata">

**Author:** ![Flash7](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Flash7](https://forums.unrealengine.com/u/Flash7)\
**Post date:** [February 10, 2017, 5:07pm UTC](https://forums.unrealengine.com/t/how-to-set-the-file-target-for-a-high-res-screenshot/312470/3 "2017-02-10T17:07:33Z")

</div>

The problem is in

```
void FScreenshotRequest::CreateViewportScreenShotFilename(FString& InOutFilename)
{
	FString TypeName;

	if(GIsDumpingMovie)
	{
		TypeName = TEXT("MovieFrame");

		if(GIsDumpingMovie > 0)
		{
			// <=0:off (default), <0:remains on, >0:remains on for n frames (n is the number specified)
			--GIsDumpingMovie;
		}
	}
	else if(GIsHighResScreenshot)
	{
		TypeName = TEXT("HighresScreenshot");
	}
	else
	{
		TypeName = InOutFilename.IsEmpty() ? TEXT("ScreenShot") : InOutFilename;
	}
	check(!TypeName.IsEmpty());

	//default to using the path that is given
	InOutFilename = TypeName;
	if (!TypeName.Contains(TEXT("/")))
	{
		InOutFilename = FPaths::ScreenShotDir() / TypeName;
	}
}

```

that function is called by FScreenshotRequest::RequestScreenshot

```
	FString GeneratedFilename = InFilename;
	CreateViewportScreenShotFilename(GeneratedFilename);

```

Inside RequestScreenshot() it sets a private variable “FileName” that is used to take screenshots. Thus, for high res screenshots file name will be always “HighresScreenshot” and placed in a default directory. And there is no way to change it…

The only solution I’m thinking of is to subscribe to OnScreenshotCaptured delegate and replace files once screenshot is taken.

---

<div class="post-metadata">

**Author:** ![Flash7](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Flash7](https://forums.unrealengine.com/u/Flash7)\
**Post date:** [February 10, 2017, 5:22pm UTC](https://forums.unrealengine.com/t/how-to-set-the-file-target-for-a-high-res-screenshot/312470/4 "2017-02-10T17:22:42Z")

</div>

Actually, if you set up a delegate there will be no saving, but you will get a bit map and its size. Like that you can handle saving yourself.  
See code: void UGameViewportClient::ProcessScreenShots(FViewport\* InViewport)

---

<div class="post-metadata">

**Author:** ![Flash7](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Flash7](https://forums.unrealengine.com/u/Flash7)\
**Post date:** [February 10, 2017, 6:29pm UTC](https://forums.unrealengine.com/t/how-to-set-the-file-target-for-a-high-res-screenshot/312470/5 "2017-02-10T18:29:23Z")

</div>

And this is how you basically do it:

```
		UGameViewportClient* ViewportClient = TheWorld->GetGameViewport();
		ViewportClient->OnScreenshotCaptured().Clear();
		ViewportClient->OnScreenshotCaptured().AddLambda(
			[ScreenshotFilePath](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, *ScreenshotFilePath);
		});
```

---

<div class="post-metadata">

**Author:** ![Saddty](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Saddty](https://forums.unrealengine.com/u/Saddty)\
**Post date:** [June 28, 2017, 6:59am UTC](https://forums.unrealengine.com/t/how-to-set-the-file-target-for-a-high-res-screenshot/312470/6 "2017-06-28T06:59:08Z")

</div>

Man, thank you very much. The body of your lambda function works perfectly.

---

<div class="post-metadata">

**Author:** ![Flash7](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Flash7](https://forums.unrealengine.com/u/Flash7)\
**Post date:** [June 28, 2017, 1:06pm UTC](https://forums.unrealengine.com/t/how-to-set-the-file-target-for-a-high-res-screenshot/312470/7 "2017-06-28T13:06:31Z")

</div>

you are welcome!

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_1e5a68a1](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_1e5a68a1](https://forums.unrealengine.com/u/anonymous_user_1e5a68a1)\
**Post date:** [November 6, 2017, 6:06am UTC](https://forums.unrealengine.com/t/how-to-set-the-file-target-for-a-high-res-screenshot/312470/8 "2017-11-06T06:06:24Z")

</div>

ScreenshotFilePath and CleanSlotFileName error?

---

<div class="post-metadata">

**Author:** ![R1ICO](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@R1ICO](https://forums.unrealengine.com/u/R1ICO)\
**Post date:** [April 7, 2018, 2:42am UTC](https://forums.unrealengine.com/t/how-to-set-the-file-target-for-a-high-res-screenshot/312470/9 "2018-04-07T02:42:44Z")

</div>

Is there a way I can do this? with BluePrints? Please help

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_32164f80](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_32164f80](https://forums.unrealengine.com/u/anonymous_user_32164f80)\
**Post date:** [August 10, 2018, 10:32am UTC](https://forums.unrealengine.com/t/how-to-set-the-file-target-for-a-high-res-screenshot/312470/10 "2018-08-10T10:32:51Z")

</div>

I have used Flash7’s solution but don’t have a good c++/UE background so here’s my (possibly mistaken!) interpretation of what’s happening for anyone else who is struggling to understand how to use the provided solution:

- The aim is to record high-resolution images from the Unreal Engine viewport. It’s possible to move the viewport view to a specified camera by calling the SetViewTarget method on a player controller, so by placing a camera in the game you can move to that camera and record the corresponding image.
- As outlined in the original question,

> I can save a regular screenshot to a location, and I can save a high-res screenshot to the default Screenshot directory, but I can’t seem to do both at once.

- (If anyone can clarify this further please do) The solution is to add a lambda function (good outline of lambda functions [here](https://www.cprogramming.com/c++11/c++11-lambda-closures.html)) to the OnScreenCaptured method of the GameViewportClient (the engine’s interface to a game viewport). The lambda function essentially takes the gameviewport image as a bitmap and then saves it to a specified file path when a screenshot request is made. When GetWorld()-\>GetGameViewport()-\>Viewport-\>TakeHighResScreenShot(); is called, the onscreenshotcaptured method (an Accessor for delegate called when a screenshot is captured) is called, which executes the code in the lambda function as outlined above.

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_32164f80](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_32164f80](https://forums.unrealengine.com/u/anonymous_user_32164f80)\
**Post date:** [August 10, 2018, 10:33am UTC](https://forums.unrealengine.com/t/how-to-set-the-file-target-for-a-high-res-screenshot/312470/11 "2018-08-10T10:33:12Z")

</div>

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();

```

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_ed079f68](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_ed079f68](https://forums.unrealengine.com/u/anonymous_user_ed079f68)\
**Post date:** [April 26, 2019, 7:06pm UTC](https://forums.unrealengine.com/t/how-to-set-the-file-target-for-a-high-res-screenshot/312470/12 "2019-04-26T19:06:31Z")

</div>

Check this: [How to take a High Res Screenshot in Play Mode (UE4) | Chiaro's](https://chiaroscorner.wordpress.com/2018/02/20/how-to-take-a-high-res-screenshot-in-play-mode-ue4/comment-page-1/)

---

<div class="post-metadata">

**Author:** ![Veseliy](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/veseliy/32/600830_2.png) [@Veseliy](https://forums.unrealengine.com/u/Veseliy)\
**Post date:** [July 16, 2020, 5:48am UTC](https://forums.unrealengine.com/t/how-to-set-the-file-target-for-a-high-res-screenshot/312470/13 "2020-07-16T05:48:12Z")

</div>

I do not know if this is still relevant, but I’ve found another way (probably a change of 4.25)  
There is an option to override file name in the **GetHighResScreenshotConfig()**  
here is an working example:

```
FString FullFileName = "C:/Temp/temp.png";
GIsHighResScreenshot = true;
GetHighResScreenshotConfig().SetFilename(FullFileName);
FScreenshotRequest::RequestScreenshot(FullFileName, false, false);
```

---

<div class="post-metadata">

**Author:** ![XzyK77](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@XzyK77](https://forums.unrealengine.com/u/XzyK77)\
**Post date:** [May 21, 2024, 2:32am UTC](https://forums.unrealengine.com/t/how-to-set-the-file-target-for-a-high-res-screenshot/312470/14 "2024-05-21T02:32:44Z")

</div>

This Post has greatly helped me. A few Years have gone by, its 2024, and Unreal 5.4 just came out. Here is some updated code for my fellow dev looking to make this work.

```auto
#include "Engine.h"
#include "HighResScreenshot.h"
#include "ImageUtils.h"
#include "Misc/FileHelper.h"
#include "Containers/ArrayView.h"

void AGimbal_Core::takeGimbalHighResCapture(FString filePath)
 {
	GIsHighResScreenshot = true;
	GetHighResScreenshotConfig().ResolutionMultiplier = 2;
	//Configure High Res Screenshot. Include params if desired...
	UGameViewportClient* ViewportClient = GetWorld()->GetGameViewport();
	//Prevents the overwrite of previously taken HighResScreenshots.
	ViewportClient->OnScreenshotCaptured().Clear();

	//Cant use filePath as a function parameter, therefore need to 'capture' it (Captureing 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;

		TArray64<uint8> compressedBitmap;
		FImageUtils::PNGCompressImageArray(SizeX, SizeY, RefBitmap, compressedBitmap);
		FFileHelper::SaveArrayToFile(TArrayView<const uint8>(compressedBitmap), *filePath, &IFileManager::Get(), static_cast<uint32>(0)); 
                });

	GAreScreenMessagesEnabled = true;
	GetWorld()->GetGameViewport()->Viewport->TakeHighResScreenShot();
}
```
