我一直在研究一种解决方案,其中涉及从一个应用程序的代号捕获图像并将其存储在图库中,但是基于文档,我已经看到该图像是临时文件,我需要一个代码才能将该文件复制到画廊,这样我就可以随时获得它
到目前为止的代码:
String imageName = "Hello.png";
String filePath = Capture.capturePhoto();
if(filePath != null) {
try {
Util.copy(FileSystemStorage.getInstance().openInputStream(filePath), Storage.getInstance().createOutputStream(imageName));
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
我需要在替换Storage.getInstance().createOutputStream(imageName)
的地方插入代码
具有完整的画廊路径
我发现有一个名为CameraKit的本地库:
我在iOS上尝试了该演示[在iPhone 7上尝试了],当按下以捕获图像时,它导致了以下异常
=================================================================
Main Thread Checker: UI API called on a background thread: -[UIView bounds]
PID: 370, TID: 26983, Thread name: (none), Queue name: com.apple.root.default-qos.overcommit, QoS: 21
Backtrace:
4 MyApplication 0x00000001049f829c Java_com_codename1_impl_ios_IOSImplementation_getDisplayWidthImpl + 80
5 MyApplication 0x0000000104bf379c com_codename1_impl_ios_IOSNative_getDisplayWidth__ + 76
6 MyApplication 0x0000000104c05478 com_codename1_impl_ios_IOSNative_getDisplayWidth___R_int + 32
7 MyApplication 0x0000000104a0f4cc com_codename1_impl_ios_IOSImplementation_getDisplayWidth___R_int + 268
8 MyApplication 0x0000000104a1a1e4 virtual_com_codename1_impl_ios_IOSImplementation_getDisplayWidth___R_int + 96
9 MyApplication 0x0000000104a3d6a0 com_codename1_impl_ios_IOSImplementation_convertToPixels___int_boolean_R_int + 408
10 MyApplication 0x00000001049ae150 virtual_com_codename1_impl_CodenameOneImplementation_convertToPixels___int_boolean_R_int + 112
11 MyApplication 0x0000000104608b2c com_codename1_ui_Display_convertToPixels___float_R_int + 308
12 MyApplication 0x000000010466c09c com_codename1_ui_plaf_UIManager_resetThemeProps___java_util_Hashtable + 2620
13 MyApplication 0x000000010466b618 com_codename1_ui_plaf_UIManager___INIT____ + 2476
14 MyApplication 0x000000010467e090 com_codename1_ui_plaf_UIManager_getInstance___R_com_codename1_ui_plaf_UIManager + 416
15 MyApplication 0x00000001045f013c com_codename1_ui_Display_mainEDTLoop__ + 1016
16 MyApplication 0x00000001049d0e00 com_codename1_ui_RunnableWrapper_run__ + 7124
17 MyApplication 0x00000001048e7fb4 virtual_java_lang_Runnable_run__ + 160
18 MyApplication 0x0000000104875478 com_codename1_impl_CodenameOneThread_run__ + 548
19 MyApplication 0x00000001048e7fb4 virtual_java_lang_Runnable_run__ + 160
20 MyApplication 0x0000000104809a70 java_lang_Thread_runImpl___long + 1056
21 MyApplication 0x00000001047b3c04 threadRunner + 80
22 libsystem_pthread.dylib 0x00000001823f1220 <redacted> + 272
23 libsystem_pthread.dylib 0x00000001823f1110 <redacted> + 0
24 libsystem_pthread.dylib 0x00000001823efb10 thread_start + 4
2018-09-17 11:39:50.457427+0300 MyApplication[370:26983] [reports] Main Thread Checker: UI API called on a background thread: -[UIView bounds]
PID: 370, TID: 26983, Thread name: (none), Queue name: com.apple.root.default-qos.overcommit, QoS: 21
Backtrace:
4 MyApplication 0x00000001049f829c Java_com_codename1_impl_ios_IOSImplementation_getDisplayWidthImpl + 80
5 MyApplication 0x0000000104bf379c com_codename1_impl_ios_IOSNative_getDisplayWidth__ + 76
6 MyApplication 0x0000000104c05478 com_codename1_impl_ios_IOSNative_getDisplayWidth___R_int + 32
7 MyApplication 0x0000000104a0f4cc com_codename1_impl_ios_IOSImplementation_getDisplayWidth___R_int + 268
8 MyApplication 0x0000000104a1a1e4 virtual_com_codename1_impl_ios_IOSImplementation_getDisplayWidth___R_int + 96
9 MyApplication 0x0000000104a3d6a0 com_codename1_impl_ios_IOSImplementation_convertToPixels___int_boolean_R_int + 408
10 MyApplication 0x00000001049ae150 virtual_com_codename1_impl_CodenameOneImplementation_convertToPixels___int_boolean_R_int + 112
11 MyApplication 0x0000000104608b2c com_codename1_ui_Display_convertToPixels___float_R_int + 308
12 MyApplication 0x000000010466c09c com_codename1_ui_plaf_UIManager_resetThemeProps___java_util_Hashtable + 2620
13 MyApplication 0x000000010466b618 com_codename1_ui_plaf_UIManager___INIT____ + 2476
14 MyApplication 0x000000010467e090 com_codename1_ui_plaf_UIManager_getInstance___R_com_codename1_ui_plaf_UIManager + 416
15 MyApplication 0x00000001045f013c com_codename1_ui_Display_mainEDTLoop__ + 1016
16 MyApplication 0x00000001049d0e00 com_codename1_ui_RunnableWrapper_run__ + 7124
17 MyApplication 0x00000001048e7fb4 virtual_java_lang_Runnable_run__ + 160
18 MyApplication 0x0000000104875478 com_codename1_impl_CodenameOneThread_run__ + 548
19 MyApplication 0x00000001048e7fb4 virtual_java_lang_Runnable_run__ + 160
20 MyApplication 0x0000000104809a70 java_lang_Thread_runImpl___long + 1056
21 MyApplication 0x00000001047b3c04 threadRunner + 80
22 libsystem_pthread.dylib 0x00000001823f1220 <redacted> + 272
23 libsystem_pthread.dylib 0x00000001823f1110 <redacted> + 0
24 libsystem_pthread.dylib 0x00000001823efb10 thread_start + 4
2018-09-17 11:39:52.007930+0300 MyApplication[370:26735] [MC] System group container for systemgroup.com.apple.configurationprofiles path is /private/var/containers/Shared/SystemGroup/systemgroup.com.apple.configurationprofiles
2018-09-17 11:39:52.009349+0300 MyApplication[370:26735] [MC] Reading from public effective user settings.
2018-09-17 11:39:52.788626+0300 MyApplication[370:26983] Failed to create directory /var/mobile/Containers/Data/Application/02F1D9AF-FE59-4B2B-9DC8-857338A52F07/Documents/cn1storage/
2018-09-17 11:39:52.832746+0300 MyApplication[370:26983] [Unknown process name] CGContextSetAllowsAntialiasing: invalid context 0x0. If you want to see the backtrace, please set CG_CONTEXT_SHOW_BACKTRACE environmental variable.
2018-09-17 11:39:52.883682+0300 MyApplication[370:26983] [Unknown process name] CGContextSetAllowsAntialiasing: invalid context 0x0. If you want to see the backtrace, please set CG_CONTEXT_SHOW_BACKTRACE environmental variable.
2018-09-17 11:39:56.810978+0300 MyApplication[370:26735] *** Terminating app due to uncaught exception 'NSGenericException', reason: '*** -[AVCapturePhotoOutput capturePhotoWithSettings:delegate:] No active and enabled video connection'
*** First throw call stack:
(0x1827cad8c 0x1819845ec 0x188369924 0x104ded220 0x105da51dc 0x105da519c 0x105da9d2c 0x182773070 0x182770bc8 0x182690da8 0x184676020 0x18c6b0758 0x104bf3728 0x104a0ebd4 0x1049ae238 0x1045e6a8c 0x104e01230 0x104e0129c 0x182121fc0)
libc++abi.dylib: terminating with uncaught exception of type NSException
(lldb)
此致
答案 0 :(得分:0)
这会将图像复制到本地存储。您也可以将其复制到本地文件系统主目录,但不能将其复制到设备库中。
为此,您需要一个显式的API将图像文件存储在那里。有些相机和操作系统实现将图像存储在图库中,而有些则不。不幸的是,这并不是一件容易控制的事情。