Using the UnrealEd module I can successfully get a uasset thumbnail as a TArray with a call to FObjectThumbnail::AccessCompressedImageData(). I can then transfer this byte array to a different non-UE application where I can realize the image. The problem is the image colors are incorrect. I have tried many different approaches to realizing the image in the second application (C#, Java), but nothing seems to work. I have attached screen shots of both the good image and the bad. Any help would be greatly appreciated.
The image with the blue sky is the correct and desired image.
When you make byte array swap red value with blue value, you maybe setting bytes in incorrect RGB order or your C# program read them in incorrect order, since you can clearly see on the image that red is blue and blue is red
Thank you your answer is a good one! While I do not understand where or why the red and blue colors are being flipped in the process, if I swap the red with the blue in my receiving application then the image appears correct once again. Thanks again!
Hey do you mind explanning how did you convert the image into a file?
I am trying to figure it out for ages,
I tried using FFileHelper::CreateBitmap and FFileHelper::SaveArrayToFile
Thanks in advance
I got the following from a colleague. I have not used it myself, but it comes from a reliable source.
I hope it will help you.
This method will save a UTexture2D as a PNG in the content directory as “MyImage.png”. If you go into HighResScreenshotConfig.SaveImage you can see its using FImageWriter and FArchive to get the job done.
void SaveTexture2D(UTexture2D* PTexture) {
PTexture->UpdateResource();
FTexture2DMipMap* MM = &PTexture->PlatformData->Mips[0];
TArray<FColor> OutBMP;
int sz = MM->SizeX * MM->SizeY;
OutBMP.AddUninitialized(sz);
FColor* FormatedImageData = static_cast<FColor*>(MM->BulkData.Lock(LOCK_READ_ONLY));
FMemory::Memcpy(OutBMP.GetData(), FormatedImageData, sz * sizeof(FColor));
MM->BulkData.Unlock();
// SaveImage knows how to save the bitmap as PNG - saves to disk file
FHighResScreenshotConfig& HighResScreenshotConfig = GetHighResScreenshotConfig();
HighResScreenshotConfig.SetHDRCapture(false);
FString filename = FPaths::Combine(*FPaths::ProjectContentDir(), TEXT("MyImage.png"));
bool bSaved = HighResScreenshotConfig.SaveImage(filename, OutBMP, FIntPoint(MM->SizeX, MM->SizeY));
}