private static final int PHOTO_REQUEST_TAKEPHOTO = 1;// 拍照
private static final int PHOTO_REQUEST_GALLERY = 2;// 从相册中选择
private static final int PHOTO_REQUEST_CUT = 3;// 结果
private File tempFile = new File(Environment.getExternalStorageDirectory(),
getPhotoFileName()); protected void onActivityResult(int requestCode, int resultCode, Intent data) {
switch (requestCode) {
case PHOTO_REQUEST_TAKEPHOTO:// 当选择拍照时调用
startPhotoZoom(Uri.fromFile(tempFile));
break;
case PHOTO_REQUEST_GALLERY:// 当选择从本地获取图片时
// 做非空判断,当我们觉得不满意想重新剪裁的时候便不会报异常,下同
if (data != null) {
System.out.println("11================");
startPhotoZoom(data.getData());
} else {
System.out.println("================");
}
break;
case PHOTO_REQUEST_CUT:// 返回的结果
if (data != null)
// setPicToView(data);
sentPicToNext(data);
break;
}
super.onActivityResult(requestCode, resultCode, data);
}
 // 使用系统当前日期加以调整作为照片的名称
private String getPhotoFileName() {
Date date = new Date(System.currentTimeMillis());
SimpleDateFormat dateFormat = new SimpleDateFormat(
"'IMG'_yyyyMMdd_HHmmss");
return dateFormat.format(date) + ".jpg";
}

调用系统拍照功能:

Intent cameraintent = new Intent(
MediaStore.ACTION_IMAGE_CAPTURE);
// 指定调用相机拍照后照片的储存路径
cameraintent.putExtra(MediaStore.EXTRA_OUTPUT,
Uri.fromFile(tempFile));
startActivityForResult(cameraintent,
PHOTO_REQUEST_TAKEPHOTO);

调用系统相册功能:

Intent getAlbum = new Intent(Intent.ACTION_GET_CONTENT);
getAlbum.setType("image/*");
startActivityForResult(getAlbum, PHOTO_REQUEST_GALLERY);

调用系统裁剪功能:

private void startPhotoZoom(Uri uri) {
Intent intent = new Intent("com.android.camera.action.CROP");
intent.setDataAndType(uri, "image/*");
// crop为true是设置在开启的intent中设置显示的view可以剪裁
intent.putExtra("crop", "true"); // aspectX aspectY 是宽高的比例
intent.putExtra("aspectX", 1);
intent.putExtra("aspectY", 1); // outputX,outputY 是剪裁图片的宽高
intent.putExtra("outputX", 300);
intent.putExtra("outputY", 300);
intent.putExtra("return-data", true);
intent.putExtra("noFaceDetection", true);
System.out.println("22================");
startActivityForResult(intent, PHOTO_REQUEST_CUT);
}

自定义对话框:

        mDialog = new AlertDialog.Builder(this, R.style.FullScreenDialog)
.create();
if (mDialog != null && !mDialog.isShowing()) {
mDialog.show();
mDialog.setContentView(R.layout.dialog_select_imge);
mDialog.setCanceledOnTouchOutside(false);
}

自定义style :

<style name="FullScreenDialog" parent="android:style/Theme.Dialog">
<item name="android:windowNoTitle">true</item>
<item name="android:windowFrame">@null</item>
<item name="android:windowIsFloating">true</item>
<item name="android:windowIsTranslucent">false</item>
<item name="android:background">@android:color/transparent</item>
<item name="android:windowBackground">@android:color/transparent</item>
<item name="android:backgroundDimEnabled">true</item>
</style>

最新文章

  1. R语言学习笔记之: 论如何正确把EXCEL文件喂给R处理
  2. Node.js系列基础学习----安装,实现Hello World, REPL
  3. mysql 5.6.17 x64 安装
  4. 领域驱动开发推荐代码示例 — Microsoft NLayerApp
  5. 字符编码的过滤器Filter(即输入的汉字,能在页面上正常显示,不会出现乱码)
  6. 通过GeoIP2分析访问者IP获取地理位置信息
  7. table转list
  8. C++类的数组元素查找最大值问题
  9. jQuery 子元素选择
  10. 第3章 Java语言基础----static
  11. UIView的基本属性及ANimation
  12. Appium (win7系统)环境搭建----完整版
  13. c# 【MVC】WebApi通过HttpClient来调用Web Api接口
  14. 左边label随着右边textarea高度自适应
  15. 【linux】linux下能ping通ip 但是不能ping通域名
  16. python之if循环
  17. CodeForces - 710F:String Set Queries (二进制分组 处理 在线AC自动机)
  18. OpenGL中各种坐标系的理解
  19. Sqlserver 数据库、表常用查询操作
  20. 【CF666E】Forensic Examination(后缀自动机,线段树合并)

热门文章

  1. AC日记——严酷的训练 洛谷 P2430
  2. gulp配合vue压缩代码格式化
  3. 六十五 async/await
  4. 阿里云Maven仓库配置,Maven镜像配置
  5. Ionic-wechat项目边开发边学(四):可伸缩输入框,下拉刷新, 置顶删除
  6. 【javascript】基于javascript的小时钟
  7. 【SQL】将特定的元素按照自己所需的位置排序
  8. nodemon 基本配置与使用
  9. 【CodeVS 2845】排序的代价
  10. [CODECHEF]LCM