How to convert iOS path to an unreal path?

Getting a photo from the photos app as a UIImage I’m trying to save it as a png for use later.

This is the code to save:

NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *filePath = [[paths objectAtIndex:0] stringByAppendingPathComponent:@"Image.png"];

// Save image.
[UIImagePNGRepresentation(image) writeToFile:filePath atomically:YES];

The filePath is of the form:

/var/mobile/Containers/Data/Application/MY-APPCODE/Documents/Image.png

And I would like to convert this to a UE4 readable path (i.e. one where FPaths::FileExists will return true).

How?

Still interested in the real answer but worked around it by saving the NSData (UIImagePNGRepresentation) data using unreal file functions.

Can you pls explain your solution to this problem?

In my case I’m grabbing UIImage’s from the camera / photo library.

So rather than save them directly - I work with the memory - you can 1) convert to png or jpeg file data which 2) can be saved, or 3) converted to a UTexture2d.

NSData *data = UIImageJPEGRepresentation(sourceImage, 1);
const uint8_t* bytes = (const uint8_t*)[data bytes];
long length = [data length];
UTexture2D *pTex = LoadFromMemory(bytes, length, EImageFormat::JPEG)

Example load from memory:

UTexture2D* LoadFromMemory(const uint8* pdata, int num, EImageFormat::Type fmt)
{
	IImageWrapperModule& ImageWrapperModule = FModuleManager::LoadModuleChecked<IImageWrapperModule>(FName("ImageWrapper"));
	IImageWrapperPtr ImageWrapper = ImageWrapperModule.CreateImageWrapper(fmt);
	if (!ImageWrapper.IsValid())
	{
		return nullptr;
	}

	if (!ImageWrapper->SetCompressed(pdata, num))
	{
		return nullptr;
	}

	const TArray<uint8>* UncompressedBGRA = NULL;
	if (ImageWrapper->GetRaw(ERGBFormat::BGRA, 8, UncompressedBGRA))
	{
		auto *pNewTexture = UTexture2D::CreateTransient(ImageWrapper->GetWidth(), ImageWrapper->GetHeight(), PF_B8G8R8A8);
		if (pNewTexture != nullptr)
		{
			void* TextureData = pNewTexture->PlatformData->Mips[0].BulkData.Lock(LOCK_READ_WRITE);
			FMemory::Memcpy(TextureData, UncompressedBGRA->GetData(), UncompressedBGRA->Num());
			pNewTexture->PlatformData->Mips[0].BulkData.Unlock();
			pNewTexture->UpdateResource();
			return pNewTexture;
		}
		else
		{
		}
	}
	else
	{
	}
	return nullptr;
}

Main point regarding the original post though is that once you have the bytes in a known format you can just work with the unreal file system.