I am using Unity 5.2 to generate .EXR format images using the Movie Render Queue plugin.
The .exr images are being generated correctly, with 32 bits format.
I need to read the image and load the image data in the memory to modify the colors of each pixel.
The way I’m doing it today, I believe the data is not being read correctly, because when you go through the Pixels of Image, I have the impression that Bulkdata is not storing all the values that need.
FString FilePath = TEXT("C:/PathExample");
UTexture2D* NewTexture = FImageUtils::ImportFileAsTexture2D(FilePath);
int32 imageWidth = NewTexture ->GetSizeX();
int32 imageHeigth = NewTexture ->GetSizeY();
FTexture2DMipMap* MipMapNewTexture = &NewTexture->PlatformData->Mips[0];
FByteBulkData* RawImageDataNewTexture = &MipMapNewTexture->BulkData;
FColor* FormatedImageDataNewtexture = static_cast<FColor*>(RawImageDataNewTexture->Lock(LOCK_READ_WRITE));
for (size_t y = 0; y < imageHeigth; ++y)
{
for (size_t x = 0; x < imageWidth; ++x)
{
int32 pixelIndex = x * imageHeigth + y;
if (FormatedImageDataNewtexture [pixelIndex].R == 0 &&
FormatedImageDataNewtexture [pixelIndex].G == 0 &&
FormatedImageDataNewtexture [pixelIndex].B == 0)
{
FormatedImageDataSegmentation[pixelIndex] = FColor::Red;
}
else {
FormatedImageDataSegmentation[pixelIndex] = FColor::Blue;
}
}
}
NewTexture->GetPlatformData()->Mips[0].BulkData.Unlock();
NewTexture->UpdateResource();
FImageWriteOptions option;
option.Format = EDesiredImageFormat::EXR;
option.bOverwriteFile = true;
option.bAsync = false;
UImageWriteBlueprintLibrary::ExportToDisk(NewTexture, TEXT("PathExample/NewImage.exr"), option);
Observed issues.
- When I change an image it the pixel are only changed in half of the image, as the height of the image was wrong. (The height and width of the image are correct because I use the same algorithm to generate PNG image and works perfectly)
- Image pixels values appear different from expected.
I believe the problem is at the time of reading the image, if anyone has any solution, please help me.