#include " PlatformFilemanager.h"
FPlatformFileManager::Get ().GetPlatformFile().FileExists(*InFileName)
Load Data to TArray from File
FFileHelper::LoadFileToArray (InData, *InFileName)
#include " ModuleManager.h"
#include " ImageWrapper/Public/IImageWrapperModule.h"
IImageWrapperModule& ImageWrapperModule = FModuleManager::LoadModuleChecked<IImageWrapperModule>(FName(" ImageWrapper" ));
#include " ImageWrapper/Public/IImageWrapper.h"
TSharedPtr<IImageWrapper> ImageWrapper = ImageWrapperModule.CreateImageWrapper(EImageFormat::PNG);
ImageWrapper->SetCompressed (InData.GetData(),LoadData.Num())
ImageWrapper->GetRaw(ERGBFormat::RGBA,8 ,Data)
Height = ImageWrapper->GetHeight ();
Width = ImageWrapper->GetWidth ();
ImageWrapper->SetRaw (Data->GetData (),Data->Num(),Width,Height,ERGBFormat::RGBA,8)
OutData = ImageWrapper->GetCompressed ()
#include " FileManagerGeneric.h"
FFileManagerGeneric::Get ().DirectoryExists(*OutFile)
FFileManagerGeneric::Get ().MakeDirectory(*FPaths::GetPath (OutFile), true)
FFileHelper::SaveArrayToFile (OutData, *OutFile)
TArray<FColor> uint8ToFColor (const TArray<uint8> origin)
{
TArray<FColor> uncompressedFColor;
FColor auxDst;
for (int i = 0 ; i < origin.Num (); i++)
{
auxDst.R = origin[i];
i++;
auxDst.G = origin[i];
i++;
auxDst.B = origin[i];
i++;
auxDst.A = origin[i];
uncompressedFColor.Add (auxDst);
}
return uncompressedFColor;
}
bool PNG2JPG (const FString PNGFile, const FString JPGFile)
{
check (PNGFile.EndsWith (TEXT (" .png" )) && JPGFile.EndsWith (TEXT (" .jpg" )));
TArray<uint8> PNGData;
if (!CheckFileAndLoadData (PNGFile, PNGData)) { return false ; }
IImageWrapperModule& ImageWrapperModule = FModuleManager::LoadModuleChecked<IImageWrapperModule>(FName (" ImageWrapper" ));
TSharedPtr<IImageWrapper> PNGWrapper = ImageWrapperModule.CreateImageWrapper (EImageFormat::PNG);
if (PNGWrapper&&PNGWrapper->SetCompressed (PNGData.GetData (),PNGData.Num ()))
{
const TArray<uint8>* Data = nullptr ;
if (PNGWrapper->GetRaw (ERGBFormat::RGBA, 8 , Data))
{
TSharedPtr<IImageWrapper> JPGWrapper = ImageWrapperModule.CreateImageWrapper (EImageFormat::JPEG);
if (JPGWrapper->SetRaw (
Data->GetData (),
Data->Num (),
PNGWrapper->GetWidth (),
PNGWrapper->GetHeight (),
ERGBFormat::RGBA,
8
))
{
if (!FFileManagerGeneric::Get ().DirectoryExists (*JPGFile))
{
FFileManagerGeneric::Get ().MakeDirectory (*FPaths::GetPath (JPGFile), true );
}
TArray<uint8> JPGData;
JPGData = JPGWrapper->GetCompressed ();
return FFileHelper::SaveArrayToFile (JPGData, *JPGFile);
}
}
}
return false ;
}