0

I saved a bitmap image into android internal storage. Now i want to retrieve this image that is /myphoto.jpg and share it using shareIntent. how can i read my myphoto.jpg from internal storage memory. Ideally I expect to get a file path.

    ByteArrayOutputStream outputBuffer = new ByteArrayOutputStream();
    bm.compress(Bitmap.CompressFormat.JPEG, 100, outputBuffer);
    byte[] byteImage1=outputBuffer.toByteArray();


    //save file to internal storage
    FileOutputStream outputStream;

    try {
      outputStream = context.openFileOutput("myphoto.jpg", Context.MODE_PRIVATE);
      outputStream.write(byteImage1);
      outputStream.close();
    } catch (Exception e) {
      e.printStackTrace();
    }
4

1 回答 1

1

You can get all the images from your sdcard using below code:

FileFilter filterForImageFolders = new FileFilter() 
    {            
        public boolean accept(File folder) 
        { 
            try 
            { 
                //Checking only directories, since we are checking for files within 
                //a directory 
                if(folder.isDirectory()) 
                { 
                    File[] listOfFiles = folder.listFiles(); 

                    if (listOfFiles == null) return false; 

                    //For each file in the directory... 
                    for (File file : listOfFiles) 
                    {                            
                        //Check if the extension is one of the supported filetypes                           
                        //imageExtensions is a String[] containing image filetypes (e.g. "png")
                        for (String ext : imageExtensions) 
                        { 
                            if (file.getName().endsWith("." + ext)) return true; 
                        } 
                    }                        
                } 
                return false; 
            } 
            catch (SecurityException e) 
            { 
                Log.v("debug", "Access Denied"); 
                return false; 
            } 
        } 
    };

Now use this method like this:

File extStore = Environment.getExternalStorageDirectory();
File[] imageDirs = extStore.listFiles(filterForImageFolders);
于 2013-06-07T10:47:05.070 回答