在指定路径创建文件夹,读取图片文件,缩放图片,判断文件夹是否存在,
来源:互联网 发布:软件定制价格 编辑:程序博客网 时间:2024/05/21 10:28
继续做笔记。。。
File mBaseFile = new File("mnt/sdcard/XYPicture/");
mBaseFile.exists() // 判断文件夹是否存在
String[] list = mBaseFile.list();
list.length == 0 //判断文件夹是否为空
/**
* 创建目录文件
*/
public static void createPath(String path) {
File file = new File(path);
if (!file.exists()) {
file.mkdir();
}
}
/**
* 获取图片地址列表
*
* @param file
* @return
*/
private static ArrayList<String> imagePath(File file) {
ArrayList<String> list = new ArrayList<String>();
File[] files = file.listFiles();
for (File f : files) {
list.add(f.getAbsolutePath());
}
Collections.sort(list);
return list;
}
/**
* 读取sdcard文件夹中的图片,并生成略缩图
*
* @return
* @throws FileNotFoundException
*/
private Map<String, Bitmap> buildThum() throws FileNotFoundException {
// 使用TreeMap,排序问题就不需要纠结了
Map<String, Bitmap> maps = new TreeMap<String, Bitmap>();
if (mBaseFile != null && mBaseFile.exists()) {
mPathLists = imagePath(mBaseFile);
if (!mPathLists.isEmpty()) {
for (int i = 0; i < mPathLists.size(); i++) {
BitmapFactory.Options options = new BitmapFactory.Options();
options.inJustDecodeBounds = true; // 设置了此属性一定要记得将值设置为false
Bitmap bitmap = BitmapFactory.decodeFile(mPathLists.get(i),
options);
options.inJustDecodeBounds = false;
bitmap = BitmapFactory.decodeFile(mPathLists.get(i),
options);
maps.put(mPathLists.get(i),
Utilities.zoomBitmap(bitmap, 278, 136));//强行缩放图片的方法
}
}
}
return maps;
}
/**
* 缩放图片
*
* @param bitmap
* 原始图片
* @param w
* 缩放之后的宽
* @param h
* 缩放之后的高
* @return
*/
static public Bitmap zoomBitmap(Bitmap bitmap, int w, int h) {
int width = bitmap.getWidth();
int height = bitmap.getHeight();
Matrix matrix = new Matrix();
float scaleWidht = ((float) w / width);
float scaleHeight = ((float) h / height);
Log.i(TAG, "width:" + width + " height:" + height + " w:" + w + " h:"
+ w);
/*
* 通过Matrix类的postScale方法进行缩放
*/
matrix.postScale(scaleWidht, scaleHeight);
Bitmap newbmp = Bitmap.createBitmap(bitmap, 0, 0, width, height,
matrix, true);
return newbmp;
}
- 在指定路径创建文件夹,读取图片文件,缩放图片,判断文件夹是否存在,
- 读取指定文件夹里面的所有图片取出里面其中一张图片和判断文件夹或文件是否存在
- 判断路径文件夹是否存在,不存在创建
- 判断文件是否存在及创建文件夹
- java 创建文件夹 创建文件 判断文件夹是否存在。。。。。
- 判断指定文件夹是否存在
- 用DirectoryExists和FileExists判断指定路径下是否存在指定的文件夹或文件
- python判断文件和文件夹是否存在、创建文件夹
- Java 判断文件夹、文件是否存在、否则创建文件夹
- Java 判断文件夹、文件是否存在、否则创建文件夹
- python判断文件和文件夹是否存在、创建文件夹
- python判断文件和文件夹是否存在、创建文件夹
- python判断文件和文件夹是否存在、创建文件夹
- Java 判断文件夹、文件是否存在、否则创建文件夹
- python判断文件和文件夹是否存在、创建文件夹
- Java 判断文件夹、文件是否存在、否则创建文件夹
- Java 判断文件夹、文件是否存在、否则创建文件夹
- Java 判断文件夹、文件是否存在、否则创建文件夹
- AFN同步异步请求
- shell中for循环总结
- 杂乱笔记
- 掌握VS2010调试 -- 入门指南
- JVM类加载机制入门总结
- 在指定路径创建文件夹,读取图片文件,缩放图片,判断文件夹是否存在,
- 5、文件的压缩与打包
- Android之Adapter系列之SimpleAdapter类
- AngularJS筛选器
- js中比较时间大小
- kprobes
- 关于Android4.4以后沉浸式自定义状态栏实现
- linux下编译.pc文件
- sed