简体   繁体   English

android-从图库显示图像

[英]android - display image from gallery

I have several images stored in content://media/external/images/media. 我在content:// media / external / images / media中存储了几张图像。 I would like to display by using ImageView and add the image view to the table. 我想显示通过使用ImageView并将图像视图添加到表中。 here is my code. 这是我的代码。

            BitmapFactory.Options options = new BitmapFactory.Options();
            options.inSampleSize = 24;
            final Bitmap b = BitmapFactory.decodeFile("content://media"+getFileLocation(), options);
            ImageView milestoneImageView = new ImageView(this);
            milestoneImageView.setImageBitmap(b);
            recordRow.addView(milestoneImageView);

When I print out the getFileLocation(), it says "/external/images/media/62". 当我打印出getFileLocation()时,它显示为“ / external / images / media / 62”。 So I added "content://media" to make a full path, but it is not working... 所以我添加了“ content:// media”来创建完整路径,但是它不起作用...

Can someone point out why the code above is not working? 有人可以指出为什么上面的代码不起作用吗?

I think "/external/images/media/62" its a Uri not a real file path.. 我认为"/external/images/media/62"是一个Uri,而不是真实的文件路径。

So instead of 所以代替

final Bitmap b = BitmapFactory.decodeFile("content://media"+getFileLocation(), options);

Just try 你试一试

final Bitmap b = BitmapFactory.decodeStream(getContentResolver().openInputStream("content://media"+getFileLocation()), null,options);

And let me know what happen.. 让我知道会发生什么..

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

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