我一直在研究一种解决方案,该解决方案涉及从代号一个应用程序捕获图像并将其存储在图库中,但根据我看到的图像是临时文件的文档,我需要一个代码将该文件复制到画廊,所以我可以随时得到它我想要的
到目前为止的代码:
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();
}
}
我需要注入(inject)替换 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)
问候,
这会将图像复制到您的本地存储中。您也可以将其复制到本地文件系统主目录,但不能将其复制到设备库中。
为此,您需要一个明确的 API 将图像文件存储在那里。一些相机和操作系统实现将图像存储在图库中,而另一些则不存储。不幸的是,这不是一般容易控制的东西。
关于android - 如何将捕获的图像保存到画廊代号一?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52354291/
欢迎光临 OGeek|极客世界-中国程序员成长平台 (http://jike.in/) | Powered by Discuz! X3.4 |