Date date = new Date(System
.currentTimeMillis());
dateTime = date.getTime() + "";
File f = new File(CacheUtils
.getCacheDirectory(
ChoosePicsActivity.this,
true, "pic")
+ dateTime);
if (f.exists()) {
f.delete();
}
try {
f.createNewFile();
} catch (IOException e) {
e.printStackTrace();
}
Uri uri = Uri.fromFile(f);
Log.e("uri", uri + "");
Intent openAlbumIntent = new Intent(
Intent.ACTION_GET_CONTENT);
openAlbumIntent
.setDataAndType(
MediaStore.Images.Media.EXTERNAL_CONTENT_URI,
"image/*");
startActivityForResult(openAlbumIntent,
REQUEST_CODE_ALBUM);
ContentResolver resolver = getContentResolver();
// 照片的原始资源地址
Uri originalUri = data.getData();
System.out.println(originalUri.toString());
try {
// 使用ContentProvider通过URI获取原始图片
Bitmap photo = MediaStore.Images.Media.getBitmap(resolver,
originalUri);
if (photo != null) {
// 为防止原始图片过大导致内存溢出,这里先缩小原图显示,然后释放原始Bitmap占用的内存
Bitmap smallBitmap = ImageTools
.zoomBitmap(photo, photo.getWidth() / SCALE,
photo.getHeight() / SCALE);
// 释放原始图片占用的内存,防止out of memory异常发生
photo.recycle();
targeturl = saveToSdCard(smallBitmap);
datas.add(targeturl);
System.out.println(targeturl.toString());
myadapter.notifyDataSetChanged();
// head.setImageDrawable(new BitmapDrawable(smallBitmap));
}
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}