感谢您的帮助。
我想获得一个FileInputStream对象,用户从图片库中选择一个图像。这是android.provider.MediaStore.Images.Media.INTERNAL_CONTENT_URI返回android的URI
内容://媒体/外部/图片/媒体/ 3
当我试图从该对象建立一个java URI对象,我得到异常的说明预计文件方案,URI一个IllegalArgumentException:内容://媒体/外部/图片/媒体/ 3 而android的URI显示计划为内容
从未发现原来的问题的解决方案。但是,如果你想要在图片库的图像的字节流,这片code能做到这一点。
位图位= Media.getBitmap(getContentResolver(),imageUri);
ByteArrayOutputStream字节=新ByteArrayOutputStream();
bitmap.com preSS(Bitmap.Com pressFormat.JPEG,40个字节);
ByteArrayInputStream进行的FileInputStream =新ByteArrayInputStream的(bytes.toByteArray());
解决方案
您可以在java URI的字符串基于构造的组合使用android的URI的toString方法
android.net.URI AURI =新android.net.URI(什么都);
java.net.URI中的树里=新java.net.URI中(auri.toString());
Android的URI | Java的URI
Thanks for any help.
I am trying to get a FileInputStream object on an image that the user selects from the picture gallery. This is the android URI returned by android.provider.MediaStore.Images.Media.INTERNAL_CONTENT_URI
content://media/external/images/media/3
When I try to construct a java URI object from this object, I get an IllegalArgumentException with the exception description Expected file scheme in URI: content://media/external/images/media/3 whereas the android URI shows the scheme as content
Never found a solution for the original question. But if you want the byte stream of an image in the pictures gallery, this piece of code will do that.
Bitmap bitmap = Media.getBitmap(getContentResolver(), imageUri);
ByteArrayOutputStream bytes = new ByteArrayOutputStream();
bitmap.compress(Bitmap.CompressFormat.JPEG, 40, bytes);
ByteArrayInputStream fileInputStream = new ByteArrayInputStream(bytes.toByteArray());
解决方案
You could use the toString method of the android URI in combination of the String based constructor of the java URI
android.net.URI auri = new android.net.URI(what ever);
java.net.URI juri = new java.net.URI(auri.toString());
Android URI | Java URI