0

I am new to swift and I am trying the CoreML feature using React Native.

I have a source file with URL as string. I convert that string to URL using

let imageURL = URL(fileURLWithPath: source)

and I tried printing out the source which is of type string and it contains the absolutePath to the file

file:///var/mobile/Containers/Data/Application/9C4D58FD-C817-47CB-A418-04BA30863C24/Library/Caches/Camera/133F8168-356A-436C-B7AF-557FA1C4F68F.jpg"

After that, I try to make the CIImage by using

let image = CIImage.init(contentsOf: imageURL);

But when I try to print image, it returns nil. I searched a bit and tried using guard but no luck. Any help will be appreciated. Thanks in advance.

Rachit
  • 208
  • 4
  • 19

1 Answers1

0

The CIImage does not create the image from a server URL. You can achieve this by first downloading the file at local location. And use the local file URL to create CIImage and then set it. The referred question/answer achieves the same, please check Loading/Downloading image from URL on Swift

If you still face issues do let me know. All the best!

Pankaj Kulkarni
  • 553
  • 4
  • 12
  • Hi, thanks for your reply. As mentioned, I am not downloading the image from any server. I am just clicking a photo and the photo is saved in the local cache. – Rachit Nov 17 '18 at 07:31
  • Not really, I passed the base64 image instead of the filepath (which kind of solved my issue) but I still want to know how to solve the problem – Rachit Nov 26 '18 at 08:44