本文主要是介绍android 取得本地相册相片或者照相即照相后取出图片,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
//打开相册去图片或者照相
》public void OpenGallery() {//相册
Intent intent = new Intent(Intent.ACTION_PICK);intent.setType("image/*");
startActivityForResult(intent, PHOTO_REQUEST_GALLERY);
}
private File mTempFile;
public void OpenCamera(Context context) {//拍照
Intent intent = new Intent("android.media.action.IMAGE_CAPTURE");
String picPath = FileOperatUtils.hasSDcardOnCreateFile();
if (StringUtils.isEmpty(picPath)) {
Toast.makeText(context, "SD卡不存在,无法使用拍照!", Toast.LENGTH_LONG).show();
return;
}
mTempFile = new File(picPath,
"IMG_"
+ DataFormatUtils.timeStampToYMDhHSM(System
.currentTimeMillis()) + ".jpg");
Uri uri = Uri.fromFile(mTempFile);
intent.putExtra(MediaStore.EXTRA_OUTPUT, uri);
startActivityForResult(intent, PHOTO_REQUEST_CAREMA);
}
》@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
String picPath = null;
if (requestCode == PHOTO_REQUEST_GALLERY) {// 相册
if (data != null) {
Uri uri = data.getData();
String schemeStr = data.getScheme().toString();
if (schemeStr.compareTo("file") == 0) {
picPath = uri.toString();
picPath = picPath.replace("file://", "");
} else if (schemeStr.compareTo("content") == 0) {
String[] filePathColumn = { MediaStore.Images.Media.DATA };
Cursor cursor = null;
cursor = mContext.getContentResolver().query(uri,
filePathColumn, null, null, null);
if (cursor != null && cursor.moveToFirst()) {
int columnIndex = cursor
.getColumnIndex(filePathColumn[0]);
picPath = cursor.getString(columnIndex);
cursor.close();
}
}
}
} else if (requestCode == PHOTO_REQUEST_CAREMA) {// 拍照
if(resultCode != 0){
if (FileOperatUtils.hasSdcard()) {
picPath = mTempFile.getAbsolutePath();
}
}
}
if (!StringUtils.isEmpty(picPath)) {
Bitmap bmp = ImageCompression.getBitmapFromUri(picPath);// 根据地址压缩图片
if (bmp != null) {
mBitmapList.add(0, bmp);
mGvImgsAdapter.notifyDataSetChanged();
}
}
super.onActivityResult(requestCode, resultCode, data);
}
这篇关于android 取得本地相册相片或者照相即照相后取出图片的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!