目錄
需求
思路
1.截圖并讀取到本地
2.本地讀取圖片并轉換為紋理2d
效果展示
找了好多的解決辦法,都不管用。這個算是折中的。
需求
將當前的用戶控件(ui)截圖下來,并賦值到一個texture2d上。
我的需求:文字游戲中,點擊存檔,將當前的游戲畫面轉換為一個紋理2d,任何將紋理2d賦值到該存檔的頭圖。
思路
先截圖到本地,然后再從本地讀取成texture2d。
1.截圖并讀取到本地
參考:
UE Widget截圖功能實現-CSDN博客
.h
UFUNCTION(BlueprintCallable, Category = "MyFunc", meta = (Keywords = "ScreenShot_"))void CaptureUIScreenshot(UUserWidget* Widget ,const FString& SavePath);.cpp
void UMyScreenShotComponent::CaptureUIScreenshot(UUserWidget* Widget, const FString& SavePath)
{TSharedRef<SWidget> TargetSWidget = Widget->TakeWidget();TArray<FColor> RawData;FIntVector OutSize;bool bScreenshotSuccessful = FSlateApplication::Get().TakeScreenshot(TargetSWidget, RawData, OutSize);if (bScreenshotSuccessful) {TArray<uint8> CompressedBitmap;FImageUtils::CompressImageArray(OutSize.X, OutSize.Y, RawData, CompressedBitmap);FFileHelper::SaveArrayToFile(CompressedBitmap, *SavePath);}
}
2.本地讀取圖片并轉換為紋理2d
插件
?
效果展示
?