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
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.
<manifest ...>
<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"/>
<activity android:name="com.gluonhq.impl.charm.down.plugins.android.PermissionRequestActivity" />
</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()
.