void APluginUseActor::spotScreen(TArray<FString> &SpotImagePath, TArray<UTexture2D*> &SpotImages) {
GetWorld()->GetFirstPlayerController()->ConsoleCommand("HighResShot 1920x1080");
FTimerHandle TimeHandle;
FString ScreenShotPath = FPaths::ScreenShotDir();
IFileManager& MyFileManager = IFileManager::Get();
TArray<FString> AssetName;
if (MyFileManager.DirectoryExists(*ScreenShotPath))
{
MyFileManager.FindFiles(AssetName, *ScreenShotPath);
}
GEngine->AddOnScreenDebugMessage(-1, 10.f, FColor::Red, ScreenShotPath);
for (FString output : AssetName) {
GetWorld()->GetTimerManager().SetTimer(TimeHandle, this, &APluginUseActor::DelayDo, 1.f, false);
SpotImagePath.Add(output);
SpotImagePathGlobal.Add(output); UTexture2D* Image = LoadTexture(FPaths::ScreenShotDir() + output);
if (Image != nullptr) {
SpotImages.Add(Image);
}
GEngine->AddOnScreenDebugMessage(-1, 10.f, FColor::Red, output);
}
}
UTexture2D* APluginUseActor::LoadTexture(const FString& path) {
UTexture2D* Texture = nullptr;
TArray<uint8> Data;
if (!FFileHelper::LoadFileToArray(Data, *path)) {
return nullptr;
}
TSharedPtr<IImageWrapper> ImageWrapper = GetImageWrapper(path);
if (ImageWrapper.IsValid() && ImageWrapper->SetCompressed(Data.GetData(), Data.Num())) {
TArray<uint8> ConRGB;
if (ImageWrapper->GetRaw(ERGBFormat::RGBA, 8, ConRGB)) {
Texture = UTexture2D::CreateTransient(ImageWrapper->GetWidth(), ImageWrapper->GetHeight(), PF_R8G8B8A8);
void* TextureData = Texture->PlatformData->Mips[0].BulkData.Lock(LOCK_READ_WRITE);
FMemory::Memcpy(TextureData, ConRGB.GetData(), ConRGB.Num());
Texture->PlatformData->Mips[0].BulkData.Unlock();
Texture->UpdateResource();
}
}
return Texture;
}
TSharedPtr<class IImageWrapper> APluginUseActor::GetImageWrapper(const FString& path) {
IImageWrapperModule& module = FModuleManager::LoadModuleChecked<IImageWrapperModule>(FName("ImageWrapper"));
if (path.EndsWith(".png")) {
return module.CreateImageWrapper(EImageFormat::PNG);
}
if (path.EndsWith(".jpg")) {
return module.CreateImageWrapper(EImageFormat::JPEG);
}
return nullptr;
}