Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

Result of Viewport->ReadPixel color is 0

I make take screenshot. But it is only works on editor.

This is my Take Screenshot smaple code.

 UGameViewportClient* GameViewport = GWorld->GetGameViewport();

 FViewport* Viewport = GameViewport->Viewport;

 FReadSurfaceDataFlags ReadPixelFlags(RCM_MinMaxNorm);

 // Read the contents of the viewport into an array.

 TArray<FColor>  Bitmap;
 if (Viewport->ReadPixels(Bitmap, ReadPixelFlags))
     check(Bitmap.Num() == Viewport->GetSizeXY().X * Viewport->GetSizeXY().Y);

     // Initialize alpha channel of bitmap
     for (auto& Pixel : Bitmap)
         Pixel.A = 255;
 // Create screenshot folder if not already present.
 if (IFileManager::Get().MakeDirectory(*FPaths::ScreenShotDir(), true))
     // Save the contents of the array to a bitmap file.
     FHighResScreenshotConfig& HighResScreenshotConfig = GetHighResScreenshotConfig();

     HighResScreenshotConfig.bDumpBufferVisualizationTargets = true;

     FString ScreenshotSaveName;
     FFileHelper::GenerateNextBitmapFilename(_fileDirectory / _fileName, TEXT("png"), ScreenshotSaveName);
     HighResScreenshotConfig.SaveImage(ScreenshotSaveName, Bitmap, GameViewport->Viewport->GetSizeXY());

I got a good image from the editor, but not from Standalong. It only output black images. (Inserted alpha value.)

This is Result Imagealt text

What is problem?

Product Version: UE 4.14
qwqw00000.png (17.7 kB)
more ▼

asked Mar 30 '17 at 09:33 AM in C++ Programming

avatar image

31 1 3 7

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

1 answer: sort voted first

I used the function that UE4 made. Like this

 FScreenshotRequest::RequestScreenshot(_fileDirectory + TEXT("/") + _fileName + TEXT(".png"), bShowUI, bAddFilenameSuffix);

But i don't know that why viewport pixle result is 0. I want someone tell me.

more ▼

answered Mar 31 '17 at 03:03 AM

avatar image

31 1 3 7

avatar image Carlizor Apr 16 '19 at 08:10 PM

You can only call ReadPixels inside of the Draw function of Viewport class.

You can check the full comment out here: https://forums.unrealengine.com/development-discussion/c-gameplay-programming/21499-fviewport-readpixels-crash-while-play-on-standalone-game-mode?p=255703#post255703

(comments are locked)
10|2000 characters needed characters left
Viewable by all users
Your answer
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question