1 保存FTexture2DRHIRef为图片

代码如下,开箱即用:

void SaveFTexture2DRHIRefToPNG(const FTexture2DRHIRef& BackBuffer,const FString& filePath)
{
    FRHICommandListImmediate& RHICmdList = FRHICommandListExecutor::GetImmediateCommandList();
    FIntRect Rect(0, 0, BackBuffer->GetSizeX(), BackBuffer->GetSizeY());
    TArray<FColor> Data;
    RHICmdList.ReadSurfaceData(BackBuffer, Rect, Data, FReadSurfaceDataFlags(RCM_UNorm));

    // 一定要加这个,不然图片透明度一直为最大成为全透明图片
    for (FColor& color : outBMP)
    {
        color.A = 255;
    }

    TArray<uint8> compressedBitmap;
    FImageUtils::CompressImageArray(BackBuffer->GetSizeX(), BackBuffer->GetSizeY(), Data, compressedBitmap);
    FFileHelper::SaveArrayToFile(compressedBitmap, *filePath);
}

如果您觉得对您有帮助,可以请站长喝一杯咖啡哦!

支付宝或者微信扫描二维码

对站长进行赞助

支付宝扫一扫

微信扫一扫

金额随意,礼清义重

当前分类随机文章推荐

全站随机文章推荐

关于本站站长 StubbornHuang
UnrealEngine4 – 将FTexture2DRHIRef保存为图片-StubbornHuang Blog纵使晴明无雨色,入云深处亦沾衣。