Calling
File picturesDir = Services.get(StorageService.class)
.flatMap(s -> s.getPublicStorage("Pictures"))
.orElseThrow(() -> new RuntimeException("Error retrieving public storage"));
for (File pic : picturesDir.listFiles()) {
System.out.println("file " + pic.getName());
}
lists no files. I think it should list all files from my Image-Gallery on iPhone.
Calling s.getPublicStorage("") it lists two folders though: gluon, Pictures.
How can i access it properly?
As discussed previously in this question, on mobile there is no Swing or AWT, so once you have a JavaFX image, to retrieve it you can't use
SwingFXUtils
.The solution proposed in the mentioned question works on Android as you can easily get the File. On iOS, on the contrary, the file is located in the gallery and the current Charm Down
PicturesService
doesn't access the gallery.Instead of modifying that service (with native code like this one), the idea to get a byteArray from the JavaFX
Image
that you can send to a web service is based on two steps:If you check the iOS implementation for
PicturesService::takePhoto
, the image from the iOS native layer is sent to the JavaFX layer via Base64 encoding and decoding.Solution 1
This code snippet works for me:
You can check the process works by reversing these steps and creating an image out of the encoded string:
Solution 2
If you want to transform the byte array from
PixelReader::getPixels
into aBufferedImage
, that won't work: the byte arrays are different.So you need to use something that the buffered image will be able to process.
Having a look at the
SwingFXUtils
implementation, it uses an int array instead.So this is another possibility:
Now you will have to decode the string, get the int array and create the buffered image: