繁体   English   中英

如何直接从相机应用程序获取捕获的图像并将其上传到网页

[英]How to get the captured image from the camera app directly and upload to a web page

我有一个问题要使用android相机应用程序保存照片。 我用输入元素制作了HTML5文件,例如:

<input type="file" accept="image/*;capture=camera" />

这样,我就可以捕获照片,在相机应用程序后显示捕获的照片,并且当我点击照片下方的保存按钮时,照片直接返回到html对象。 当我尝试在网络视图中打开此页面时,我发现我必须做一些技巧。 到现在为止还挺好。 我能够打开相机并拍摄照片。 这是我的问题:如何显示最后一张照片,并将其保存到HTML对象,就像HTML5一样。 我找不到显示最后一张照片的方法。 HTML5可以轻松做到这一点,但我陷入了本机版本。 感谢您的帮助...(顺便说一句,我使用eclipse和galaxy s3来测试本机应用程序。)

这是我打开相机应用程序的代码。

活动代码:

Intent i = new Intent(Intent.ACTION_PICK);
i.addCategory(Intent.CATEGORY_DEFAULT);
i.setType("image/*");       

FileUploadTest.this.startActivityForResult(Intent.createChooser(i,"File Chooser"), 
    FILECHOOSER_RESULTCODE);

我看到没有人对此问题感兴趣。 无论如何,我找到了解决方案,并希望与任何有兴趣的人分享。

  • 不要忘记调用该方法的“超级”。

  • 不要忘记在每种情况下都调用“ onReceiveValue”。 如果您不调用它,您的应用将崩溃

 @Override protected void onActivityResult(int requestCode, int resultCode, Intent intent) { try { super.onActivityResult(requestCode, resultCode, intent); if (requestCode == CAMERA_REQUEST && resultCode == RESULT_OK) mUploadMessage.onReceiveValue(intent == null ? this.fileUri : intent.getData()); else mUploadMessage.onReceiveValue(null); } catch (Exception e) { Log.e("Error9", e.getLocalizedMessage()); mUploadMessage.onReceiveValue(null); } finally { mUploadMessage = null; } } 

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM