zoukankan      html  css  js  c++  java
  • 扫描指定目录下所有图片文件

    String myparent=newPath.substring(0, newPath.lastIndexOf("/")).substring(newPath.substring(0, newPath.lastIndexOf("/")).lastIndexOf("/")+1);  
                 Uri mImageUri = MediaStore.Images.Media.EXTERNAL_CONTENT_URI;    
                 ContentResolver mContentResolver =getContentResolver();    
                 String[] projection = { MediaStore.Images.Media._ID, MediaStore.Images.Media.BUCKET_ID, MediaStore.Images.Media.BUCKET_DISPLAY_NAME, MediaStore.Images.Media.DISPLAY_NAME,  
                        MediaStore.Images.Media.DATA };  
                 //只查询jpeg的图片    
                 Cursor mCursor = mContentResolver.query(mImageUri, projection,    
                         MediaStore.Images.Media.BUCKET_DISPLAY_NAME + "=? and (" + MediaStore.Images.Media.MIME_TYPE + "=? or " + MediaStore.Images.Media.MIME_TYPE + "=?)",  
                         new String[]{myparent, "image/jpeg", "image/png"},null);    
                 if (mCursor == null) {  
                    Toast.makeText(getBaseContext(), "请装入SD卡, 或者图库没有照片", Toast.LENGTH_SHORT).show();  
                }  
                 myimages.clear();  
                while (mCursor.moveToNext()) {  
                    // 获取的图片的id  
                    int id = mCursor.getInt(mCursor.getColumnIndex(MediaStore.Images.Media._ID));  
                    // 图片所在当前目录id  
                    int parentiD = mCursor.getInt(mCursor.getColumnIndex(MediaStore.Images.Media.BUCKET_ID));  
                    // 图片所在当前目录名称  
                    String parentname = mCursor.getString(mCursor.getColumnIndex(MediaStore.Images.Media.BUCKET_DISPLAY_NAME));  
                    // 图片名称  
                    String imagename = mCursor.getString(mCursor.getColumnIndex(MediaStore.Images.Media.DISPLAY_NAME));  
                    // 获取图片的路径  
                    String path = mCursor.getString(mCursor.getColumnIndex(MediaStore.Images.Media.DATA));  
                    ImageInfo imageInfo=new ImageInfo(id, imagename, path, parentiD, parentname);  
                    imageInfo.setId(id);  
                    imageInfo.setParentID(parentiD);  
                    imageInfo.setParentName(parentname);  
                    imageInfo.setImageName(imagename);  
                    imageInfo.setPath(path);  
                    myimages.add(imageInfo);  
                }  
                mCursor.close();
  • 相关阅读:
    ADC和RTC的寄存器的读取
    串口中断
    chengdongyue的笔记
    UART速度的问题
    tags
    strtok
    exports、module.exports和export、export default到底是咋回事
    module.exports与exports,export与export default之间的关系和区别
    Vue2.x中的Render函数
    Vue的入门之安装
  • 原文地址:https://www.cnblogs.com/exmyth/p/8428491.html
Copyright © 2011-2022 走看看