I have tried to use the function
SwingFXUtils.fromFXImage
which raises NoClassFoundError exception. How can i save an image otherwise on G
SwingFXUtils
nor any Swing related classes are supported on Android.
Based on your comments, you are using Charm Down PicturesService
to retrieve an image from the camera and show it on an ImageView
control:
Services.get(PicturesService.class).ifPresent(service ->
service.takePhoto(false).ifPresent(imageView::setImage));
And now you want to save that image into a private/public storage location on your device.
If you check the API for takePhoto
, it has a savePhoto
argument, that you can use to save the picture:
// take photo and save picture
Services.get(PicturesService.class).ifPresent(service ->
service.takePhoto(true).ifPresent(imageView::setImage));
Now if you have a look at how this is implemented, you will find your pic under the external storage for pictures:
File photo = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES), "IMG_"+ timeStamp + ".jpg");
You can access that folder easily under /sdcard/Pictures
.
Also you can use StorageService
and getPublicStorage("Pictures")
, and going through the directory you can retrieve the last file added:
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());
}