x

Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

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?

Product Version: UE 4.12
Tags:
more ▼

asked Jul 02 '16 at 10:17 PM in C++ Programming

avatar image

theonecalledtom
1.3k 60 66 270

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

1 answer: sort voted first

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

more ▼

answered Jul 04 '16 at 06:07 AM

avatar image

theonecalledtom
1.3k 60 66 270

avatar image StanRymkiewicz Aug 01 '16 at 09:43 AM

Can you pls explain your solution to this problem?

avatar image theonecalledtom Aug 01 '16 at 05:35 PM

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.

(comments are locked)
10|2000 characters needed characters left
Viewable by all users
Your answer
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question