我有一张图片保存在/data/data/my.package.name/files/mypicture.png
,我想加载它在一个布局。如何将私人文件中的图片加载到布局(Android)中?
我试过这个,但它不起作用。
File filePath = getFileStreamPath("pictureIWouldLikeToLoad.png");
ImageView img = new ImageView(getApplicationContext());
img.setImageDrawable(Drawable.createFromPath(filePath.toString()));
ViewGroup picturesLayout = (ViewGroup) findViewById(R.id.layout_pictures_area);
picturesLayout.addView(imgView);
我不明白它是如何工作的,有人可以解释我为什么吗?那么我想怎么做呢?我需要一个内容提供者吗?有没有更简单的方法来做到这一点?
有什么区别?两者通常都有效,不是吗? – cleroo 2012-08-06 07:36:23
顺便说一句,你可以直接给'decodeFile'方法这样的路径:'Bitmap bmp = BitmapFactory.decodeFile(“/ data/data/my.package.name/files/mypicture.png”);'。 – cleroo 2012-08-06 07:43:47
我把自己的答案,谢谢无论如何帮助! – cleroo 2012-08-06 08:35:11