android如何获取相册所有图片
若以下回答无法解决问题,邀请你更新回答
2个回答
展开全部
// 从本地选择图片(比如按钮触发该事件,调取系统相册)
if (Environment.getExternalStorageState().equals(
Environment.MEDIA_MOUNTED)) {
Intent getImageIntent = new Intent(Intent.ACTION_GET_CONTENT);
getImageIntent.addCategory(Intent.CATEGORY_OPENABLE);
getImageIntent.setType("image/jpeg");
startActivityForResult(getImageIntent, 4);
} else {
Toast.makeText(getApplicationContext(), "SD卡不可用", 0).show();
}
// 本地选择 结果
在activity的onactivityresult()中写:
if (data != null) {//判空
Uri uri = data.getData();
uri.getPath().toString();
ContentResolver cr = this.getContentResolver();
try {
Bitmap bmp;//压缩
BitmapFactory.Options option = new BitmapFactory.Options();
option.inJustDecodeBounds = true;
option.inPurgeable = true;
option.inInputShareable = true;
option.inSampleSize = 2;
option.inJustDecodeBounds = false;
bmp = BitmapFactory.decodeStream(cr.openInputStream(uri),
null, option);
//imageView_userLogo(view控件设置背景)
imageView_userLogo.setImageBitmap(BmpToRound
.toRoundBitmap(bmp));
File file = SaveBitmapToSdCard.saveMyBitmap(
getApplicationContext(),
"" + System.currentTimeMillis(), bmp);
startUpLoad(file);
} catch (FileNotFoundException e) {
e.printStackTrace();
}
}
if (Environment.getExternalStorageState().equals(
Environment.MEDIA_MOUNTED)) {
Intent getImageIntent = new Intent(Intent.ACTION_GET_CONTENT);
getImageIntent.addCategory(Intent.CATEGORY_OPENABLE);
getImageIntent.setType("image/jpeg");
startActivityForResult(getImageIntent, 4);
} else {
Toast.makeText(getApplicationContext(), "SD卡不可用", 0).show();
}
// 本地选择 结果
在activity的onactivityresult()中写:
if (data != null) {//判空
Uri uri = data.getData();
uri.getPath().toString();
ContentResolver cr = this.getContentResolver();
try {
Bitmap bmp;//压缩
BitmapFactory.Options option = new BitmapFactory.Options();
option.inJustDecodeBounds = true;
option.inPurgeable = true;
option.inInputShareable = true;
option.inSampleSize = 2;
option.inJustDecodeBounds = false;
bmp = BitmapFactory.decodeStream(cr.openInputStream(uri),
null, option);
//imageView_userLogo(view控件设置背景)
imageView_userLogo.setImageBitmap(BmpToRound
.toRoundBitmap(bmp));
File file = SaveBitmapToSdCard.saveMyBitmap(
getApplicationContext(),
"" + System.currentTimeMillis(), bmp);
startUpLoad(file);
} catch (FileNotFoundException e) {
e.printStackTrace();
}
}
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
2015-09-01
展开全部
下载快图
设置里面显示所有图片
设置里面显示所有图片
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询
广告 您可能关注的内容 |