How to use this snippet of saving a png!

How to use this snippet… i am currently out of any ideas… kindly guide me…

i was able to save a blank png image with this one how ever…

 bool UCustomBlueprintUtils::SaveRenderTargetToFile(UTextureRenderTarget2D *rt, const FString& fileDestination)
 {
     FTextureRenderTargetResource *rtResource = rt->GameThread_GetRenderTargetResource();
     FReadSurfaceDataFlags readPixelFlags(RCM_UNorm);
 
     TArray<FColor> outBMP;
     outBMP.AddUninitialized(rt->GetSurfaceWidth() * rt->GetSurfaceHeight());
     rtResource->ReadPixels(outBMP, readPixelFlags);
 
     FIntPoint destSize(rt->GetSurfaceWidth(), rt->GetSurfaceHeight());
     TArray<uint8> CompressedBitmap;
     FImageUtils::CompressImageArray(destSize.X, destSize.Y, outBMP, CompressedBitmap);
     bool imageSavedOk = FFileHelper::SaveArrayToFile(CompressedBitmap, *fileDestination);
 
     return imageSavedOk;
 }

Hello! TArray of FColor is just raw data, while image formats have additionally meta. For example I check out this code

FBufferArchive Buffer;
FImageUtils::ExportRenderTarget2DAsPNG(textureRenderTarget2D, Buffer);
static auto projDir = FPaths::ProjectSavedDir();
FFileHelper::SaveArrayToFile(Buffer, *FPaths::Combine(projDir, "tmp.png"));

It is working only if Render Target has only one image format RGBA8. So, you can write different code for different formats of Render Target, that’s why you firstly should decide what format will by set to Render Target and after that details will be more obvious.

any one???

Check this one Save render target to file - Rendering - Unreal Engine Forums