Download

Problem storing SceneCaptureCube TextureTarget to PNG File.

Hello together,

I currently try to store a SceneCaptureCube Texture Target to a PNG File.
My current Code:



    USceneCaptureComponentCube* SceneCaptureCube = cameraL1->GetCaptureComponentCube();
    UTextureRenderTargetCube* TC = NewObject<UTextureRenderTargetCube>();
    TC->ClearColor = FLinearColor::Black;
    TC->bHDR = false;
    TC->Init(1024, EPixelFormat::PF_B8G8R8A8);
    SceneCaptureCube->TextureTarget = TC;

    SceneCaptureCube->TextureTarget = TC;
    SceneCaptureCube->bCaptureOnMovement = true;
    SceneCaptureCube->bCaptureEveryFrame = false;
    SceneCaptureCube->bAutoActivate = true;
    SceneCaptureCube->CaptureStereoPass = EStereoscopicPass::eSSP_FULL;
    SceneCaptureCube->CaptureScene();
    TArray<FColor> TL1RawPixels;


    SceneCaptureCube->TextureTarget->GameThread_GetRenderTargetResource()->ReadPixels(TL1RawPixels);
    for (auto& Pixel : TL1RawPixels)
    {
        // Switch Red/Blue changes.
        const uint8 PR = Pixel.R;
        const uint8 PB = Pixel.B;
        Pixel.R = PB;
        Pixel.B = PR;

        // Set alpha based on RGB values of ClearColour.
        Pixel.A = ((Pixel.R == TC->ClearColor.R) && (Pixel.G == TC->ClearColor.G) && (Pixel.B == TC->ClearColor.B)) ? 0 : 255;
    }

    IImageWrapperModule& ImageWrapperModule = FModuleManager::LoadModuleChecked<IImageWrapperModule>(FName("ImageWrapper"));
    TSharedPtr<IImageWrapper> ImageWrapper = ImageWrapperModule.CreateImageWrapper(EImageFormat::PNG);
    if (ImageWrapper.IsValid() && ImageWrapper->SetRaw(&TL1RawPixels[0], TL1RawPixels.Num() * sizeof(FColor), SceneCaptureCube->TextureTarget->SizeX, SceneCaptureCube->TextureTarget->SizeX, ERGBFormat::RGBA, 8))
    {
        FString ImagePath = filePath + "cameraL1_" + FString::FromInt(ImageCounter);
        ImagePath += ".png";
        FFileHelper::SaveArrayToFile(ImageWrapper->GetCompressed(), *ImagePath);
    }


The image how it looks inside the editor:
http://prntscr.com/qq9hzv
The image how it was stored:
http://prntscr.com/qq9hkg

Have someone a idea what is wrong?

Thanks
/Mindsaver