Android Bitmap 防止OOM及其他操作


防止OOM,即压缩Bitmap图片

// 压缩图片大小
	public Bitmap reBitmap(String path) {

		BitmapFactory.Options options = new BitmapFactory.Options();
		options.inJustDecodeBounds = false;
		// 使图片大小为原来的1/4
		options.inSampleSize = 4;
		Bitmap bitmap = BitmapFactory.decodeFile(path, options);
		return bitmap;

	}

文件的重命名

File file1=new File(path);  
	File file2=new File(pastePath);  
	boolean flag = file1.renameTo(file2);

根据时间选取以时间命名的图片

// 返回图片路径
	public ArrayList<String> GetFilePath(Long commitTime) {
		// File file_ = new File(isSdcard() + photoPath);
		File file_ = new File(photoPath);
		File[] files = file_.listFiles();
		ArrayList<String> myFilePath = new ArrayList<String>();
		if (files != null) {
			Log.v("Camera", "进入判断");
			int count = files.length;
			System.out.println(count);
			for (int i = 0; i < count; i++) {
				File file = files[i];
				String filepath = file.getAbsolutePath(); // 得到路径
				Log.v("路径1---", filepath);
				
				// pathTime为拍照时间,此判断用来选择一次任务的照片
				Long pathTime = Long.parseLong(filepath.substring(
						photoPath.length(), photoPath.length()
								+ commitTime.toString().length()));
				
				if (commitTime - pathTime <= 0) {

					if (filepath.endsWith("jpg") || filepath.endsWith("gif")
							|| filepath.endsWith("bmp")
							|| filepath.endsWith("png")) {

						// 把路径存入容器中
						
						myFilePath.add(filepath);
						Log.v("路径3---", filepath);
						System.out.println("size is " + myFilePath.size());
					}

				}

			}
		}
		return myFilePath;
	}


你可能感兴趣的:(压缩,bitmap,oom,图片,筛选)