我有一个Imagebutton,让用户拍照并在界面上显示它.当我尝试获取图像URI时,它返回null:
Uri uri = data.getData();
我在互联网上进行了一些搜索,找到了类似的解决方案:
@OverrIDepublic voID onActivityResult(int requestCode,int resultCode,Intent data) { try { if (resultCode == Activity.RESulT_OK) { updateProfilePicure = Boolean.TRUE; switch(requestCode){ case 0: Bundle extras = data.getExtras(); Object xx = data.getData(); Bitmap imageBitmap = (Bitmap) extras.get("data"); Uri tempuri = getimageUri(imageBitmap); imageVIEw.setimageBitmap(imageBitmap); break; default: break; } } } catch(Exception e){ e.printstacktrace(); }}public Uri getimageUri(Bitmap inImage) { ByteArrayOutputStream bytes = new ByteArrayOutputStream(); inImage.compress(Bitmap.CompressFormat.JPEG,100,bytes); String path = MediaStore.Images.Media.insertimage( ApplicationContext.getInstance().getContext().getContentResolver(),inImage,"Title",null); return Uri.parse(path);}
对我来说,它没有意义,因为当调用转到方法onActivityResult()时,图片已经保存在DCIM文件夹中,并且没有任何理由再次保存它.那我为什么要用呢?
是否有可能找到另一种从捕获的图像中检索URI的方法?
提前致谢.
解决方法the picture is already saved on DCIM folder and don’t have any reason to save it again.
不必要.引用the documentation for ACTION_IMAGE_CAPTURE
:
The caller may pass an extra EXTRA_OUTPUT to control where this image will be written. If the EXTRA_OUTPUT is not present,then a small sized image is returned as a Bitmap object in the extra fIEld.
(这里的“额外字段”是一个额外键入的数据)
您粘贴的代码段是额外检索数据,因此图像不会存储在任何位置.
Is possible to find another way to retrIEve the URI from captured image?
您已经在第一个代码段中拥有了此代码 – 如果您在ACTION_IMAGE_CAPTURE请求中将Uri指定为EXTRA_OUTPUT,您将获得一个Uri回到在Intent中传递给onActivityResult()的图像.
总结以上是内存溢出为你收集整理的Android – 从我刚拍摄的图片中获取URI(不再保存图像)全部内容,希望文章能够帮你解决Android – 从我刚拍摄的图片中获取URI(不再保存图像)所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)