public interface PicturesService
Example
ImageView imageView = new ImageView();
Services.get(PicturesService.class).ifPresent(service -> {
service.takePhoto(false).ifPresent(image -> imageView.setImage(image));
});
It also allows the developer to retrieve the original file and work with it as needed, for instance sharing it with the ShareService.
Example
ImageView imageView = new ImageView();
Services.get(PicturesService.class).ifPresent(service -> {
service.loadFromGallery().ifPresent(image -> imageView.setImage(image));
service.getImageFile().ifPresent(file ->
Services.get(ShareService.class).ifPresent(share ->
share.share("image/jpeg", file)));
});
Android Configuration
Create the file /src/android/res/xml/file_provider_paths.xml
with
the following content that allows access to the external storage:
<?xml version="1.0" encoding="utf-8"?>
<paths>
<external-path name="external_files" path="." />
</paths>
The permission android.permission.CAMERA
needs to be added as well as the permissions
android.permission.READ_EXTERNAL_STORAGE
and android.permission.WRITE_EXTERNAL_STORAGE
to be able to read and write images. Also a provider
is required:
<manifest package="${application.package.name}" ...>
<uses-permission android:name="android.permission.CAMERA"/>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<application ...>
...
<activity android:name="com.gluonhq.impl.charm.down.plugins.android.PermissionRequestActivity" />
<provider
android:name="android.support.v4.content.FileProvider"
android:authorities="${application.package.name}.fileprovider"
android:exported="false"
android:grantUriPermissions="true">
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="@xml/file_provider_paths" />
</provider>
</application>
</manifest>
iOS Configuration
The following keys are required:
<key>NSCameraUsageDescription</key>
<string>Reason to use Camera Service (iOS 10+)</string>
<key>NSPhotoLibraryUsageDescription</key>
<string>Reason to use Photo Library (iOS 10+)</string>
<key>NSPhotoLibraryAddUsageDescription</key>
<string>Reason to use Photo Library (iOS 10+)</string>
Modifier and Type | Method and Description |
---|---|
java.util.Optional<java.io.File> |
getImageFile()
Retrieve the file associated to the original picture generated by
takePhoto(true) or the file related to the
picture selected with loadImageFromGallery() . |
java.util.Optional<javafx.scene.image.Image> |
loadImageFromGallery()
Retrieve an image from the device's gallery of images
|
java.util.Optional<javafx.scene.image.Image> |
takePhoto(boolean savePhoto)
Use the device's camera to take a photo, and retrieve an
Image . |
java.util.Optional<javafx.scene.image.Image> takePhoto(boolean savePhoto)
Image
.
It can be saved as well in the device's public album.savePhoto
- if true, image is saved to public albumjava.util.Optional<javafx.scene.image.Image> loadImageFromGallery()
java.util.Optional<java.io.File> getImageFile()
takePhoto(true)
or the file related to the
picture selected with loadImageFromGallery()
.