SwingFXUtils shows NoClassFoundError

前端 未结 1 659
悲&欢浪女
悲&欢浪女 2020-12-22 08:42

I have tried to use the function

SwingFXUtils.fromFXImage

which raises NoClassFoundError exception. How can i save an image otherwise on G

相关标签:
1条回答
  • 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());
    }
    
    0 讨论(0)
提交回复
热议问题