unreal RenderTarget存本地PNG
bool APIPCamera::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); for (FColor& color : outBMP) color.A = 255; 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; } }