简体   繁体   English

如何在android中显示保存在内部存储器上的图像文件

[英]how to display image file save on internal storage in android

i have saved drawable images in internal storage by compressing them in bitmap format.我通过以位图格式压缩它们将可绘制图像保存在内部存储中。 the problem is that i want to retrieve those image files and wants to display them in grid view i am able to list the total no of files but i am not able to display those files in image view.问题是我想检索这些图像文件并希望在网格视图中显示它们我能够列出文件总数但我无法在图像视图中显示这些文件。 here is my code这是我的代码

        Intent i = getIntent();
        int position = i.getExtras().getInt("id");
        ImageAdapter imageAdapter = new ImageAdapter(this);

        ImageView imageView = (ImageView) findViewById(R.id.SingleView); 
        ContextWrapper cw = new ContextWrapper(getApplicationContext());
           File directory = cw.getDir("imageDir", Context.MODE_PRIVATE);
           File[] imageList = directory.listFiles();
           if(imageList == null){
               imageList = new File[0];
                }
           Log.i("My","ImageList Size = "+imageList.length);


        imageView.setImageResource(imageAdapter.  (....?) );

set Image(From Sd card) to imageview get the path of the image which is in sdcard.将 Image(From Sd card) 设置为 imageview 获取 sdcard 中图像的路径。 and you can assign it by creating Bitmap你可以通过创建位图来分配它

String filePath = Environment.getExternalStorageDirectory()
                .getAbsolutePath() + File.separator + "your_image_name.png";
        Bitmap bmp = BitmapFactory.decodeFile(filePath);
        imageView.setImageBitmap(bmp);

Another way to set imageview you can also use third party library also which may have resize and Scaling options too.另一种设置图像视图的方法也可以使用第三方库,这些库也可能具有调整大小和缩放选项。 like ImageLoaderImageLoader

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

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