SwingFXUtils shows NoClassFoundError

余生颓废 提交于 2019-11-28 12:52:02

问题


I have tried to use the function

SwingFXUtils.fromFXImage

which raises NoClassFoundError exception. How can i save an image otherwise on Gluon mobile?


回答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());
}


来源:https://stackoverflow.com/questions/42032859/swingfxutils-shows-noclassfounderror

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!