Android 从名为 CameraView 的图片中获取 URI 字符串
启动相机意图:
void openCamera() {
File imageDirectory = new File("/sdcard/myprog");
if (!imageDirectory.isDirectory()) imageDirectory.mkdir();
String path = imageDirectory.toString().toLowerCase();
String name = imageDirectory.getName().toLowerCase();
ContentValues values = new ContentValues();
values.put(Media.TITLE, "Image");
values.put(Images.Media.BUCKET_ID, path.hashCode());
values.put(Images.Media.BUCKET_DISPLAY_NAME,name);
values.put(Images.Media.MIME_TYPE, "image/jpeg");
values.put(Media.DESCRIPTION, "Image capture by camera");
values.put("_data", "/sdcard/myprog/1111.jpg");
Uri uri = getContentResolver().insert( Media.EXTERNAL_CONTENT_URI , values);
Intent i = new Intent("android.media.action.IMAGE_CAPTURE");
i.putExtra(MediaStore.EXTRA_OUTPUT, uri);
startActivityForResult(i, 0);
}
然后...
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode==0 && resultCode==RESULT_OK) {
Uri path = data.getData();
...
我尝试了很多示例,在程序中用相机拍照,然后在程序中使用该图片,但是:
-i 在这里出现异常:Uri path = data.getData() ;
-或者我得到一个空值:Uri path = data.getData();
获取拍摄的相机图片网址的正确方法是什么?
谢谢,莱斯利
start camera intent:
void openCamera() {
File imageDirectory = new File("/sdcard/myprog");
if (!imageDirectory.isDirectory()) imageDirectory.mkdir();
String path = imageDirectory.toString().toLowerCase();
String name = imageDirectory.getName().toLowerCase();
ContentValues values = new ContentValues();
values.put(Media.TITLE, "Image");
values.put(Images.Media.BUCKET_ID, path.hashCode());
values.put(Images.Media.BUCKET_DISPLAY_NAME,name);
values.put(Images.Media.MIME_TYPE, "image/jpeg");
values.put(Media.DESCRIPTION, "Image capture by camera");
values.put("_data", "/sdcard/myprog/1111.jpg");
Uri uri = getContentResolver().insert( Media.EXTERNAL_CONTENT_URI , values);
Intent i = new Intent("android.media.action.IMAGE_CAPTURE");
i.putExtra(MediaStore.EXTRA_OUTPUT, uri);
startActivityForResult(i, 0);
}
and then...
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode==0 && resultCode==RESULT_OK) {
Uri path = data.getData();
...
I tried many sample to take a picture with my camera on my program, and then use that picture with my program, but:
-i get an exception here: Uri path = data.getData();
-or i get a null value to: Uri path = data.getData();
what is the correct way, to get the shoted camera picture url?
Thanks, Leslie
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
你至少需要这样做,
如果 imageDirectory 持有 Uri 的字符串表示形式
,或者我想你可以这样做,
因为你已经获得了 imagedirectory 字符串
you need to do
at least if imageDirectory is holding a string representation of a Uri
or i suppose you could just do this
since you are already getting the imagedirectory string