Android 调用前摄像头拍照存储,根据打开时横竖屏切换preview

上传者: changliangdoscript | 上传时间: 2019-12-21 19:32:28 | 文件大小: 628KB | 文件类型: rar
android调用camera时,可以自己写一个activity,赋上相关参数,打开前camera就可以了; 需要申请的permission,在AndroidManifest.xml中添加: 主要功能,打开前camera private Camera openFrontFacingCameraGingerbread() { int cameraCount = 0; Camera cam = null; Camera.CameraInfo cameraInfo = new Camera.CameraInfo(); cameraCount = Camera.getNumberOfCameras(); for (int camIdx = 0; camIdx < cameraCount; camIdx++) { Camera.getCameraInfo(camIdx, cameraInfo); if (cameraInfo.facing == Camera.CameraInfo.CAMERA_FACING_FRONT) { try { cam = Camera.open(camIdx); mCurrentCamIndex = camIdx; } catch (RuntimeException e) { Log.e(TAG, "Camera failed to open: " + e.getLocalizedMessage()); } } } return cam; } 根据打开时的横竖屏方向来调整preview角度 //根据横竖屏自动调节preview方向,Starting from API level 14, this method can be called when preview is active. private static void setCameraDisplayOrientation(Activity activity,int cameraId, Camera camera) { Camera.CameraInfo info = new Camera.CameraInfo(); Camera.getCameraInfo(cameraId, info); int rotation = activity.getWindowManager().getDefaultDisplay().getRotation(); //degrees the angle that the picture will be rotated clockwise. Valid values are 0, 90, 180, and 270. //The starting position is 0 (landscape). int degrees = 0; switch (rotation) { case Surface.ROTATION_0: degrees = 0; break; case Surface.ROTATION_90: degrees = 90; break; case Surface.ROTATION_180: degrees = 180; break; case Surface.R

文件下载

资源详情

[{"title":"( 24 个子文件 628KB ) Android 调用前摄像头拍照存储,根据打开时横竖屏切换preview","children":[{"title":"bin","children":[{"title":"classes","children":null,"spread":false}],"spread":true},{"title":"res","children":[{"title":"drawable-ldpi","children":null,"spread":false},{"title":"values-v11","children":[{"title":"styles.xml <span style='color:#111;'> 324B </span>","children":null,"spread":false}],"spread":true},{"title":"menu","children":[{"title":"main.xml <span style='color:#111;'> 439B </span>","children":null,"spread":false}],"spread":true},{"title":"values-v14","children":[{"title":"styles.xml <span style='color:#111;'> 381B </span>","children":null,"spread":false}],"spread":true},{"title":"drawable-hdpi","children":[{"title":"ic_launcher.png <span style='color:#111;'> 7.48KB </span>","children":null,"spread":false}],"spread":true},{"title":"drawable-xhdpi","children":[{"title":"ic_launcher.png <span style='color:#111;'> 12.22KB </span>","children":null,"spread":false}],"spread":true},{"title":"drawable-xxhdpi","children":[{"title":"ic_launcher.png <span style='color:#111;'> 24.20KB </span>","children":null,"spread":false}],"spread":true},{"title":"values","children":[{"title":"strings.xml <span style='color:#111;'> 273B </span>","children":null,"spread":false},{"title":"styles.xml <span style='color:#111;'> 680B </span>","children":null,"spread":false},{"title":"dimens.xml <span style='color:#111;'> 213B </span>","children":null,"spread":false}],"spread":true},{"title":"values-sw720dp-land","children":[{"title":"dimens.xml <span style='color:#111;'> 269B </span>","children":null,"spread":false}],"spread":true},{"title":"drawable-mdpi","children":[{"title":"ic_launcher.png <span style='color:#111;'> 3.69KB </span>","children":null,"spread":false}],"spread":true},{"title":"values-sw600dp","children":[{"title":"dimens.xml <span style='color:#111;'> 196B </span>","children":null,"spread":false}],"spread":true},{"title":"layout","children":[{"title":"activity_main.xml <span style='color:#111;'> 1.32KB </span>","children":null,"spread":false}],"spread":true}],"spread":false},{"title":"proguard-project.txt <span style='color:#111;'> 781B </span>","children":null,"spread":false},{"title":"ic_launcher-web.png <span style='color:#111;'> 50.19KB </span>","children":null,"spread":false},{"title":"assets","children":null,"spread":false},{"title":"gen","children":[{"title":"com","children":[{"title":"yxiaolv","children":[{"title":"camerasample","children":[{"title":"BuildConfig.java <span style='color:#111;'> 166B </span>","children":null,"spread":false},{"title":"R.java <span style='color:#111;'> 2.73KB </span>","children":null,"spread":false}],"spread":true}],"spread":true}],"spread":true}],"spread":true},{"title":"src","children":[{"title":"com","children":[{"title":"yxiaolv","children":[{"title":"camerasample","children":[{"title":"CameraActivity.java <span style='color:#111;'> 6.55KB </span>","children":null,"spread":false}],"spread":true}],"spread":true}],"spread":true}],"spread":true},{"title":".project <span style='color:#111;'> 848B </span>","children":null,"spread":false},{"title":".classpath <span style='color:#111;'> 475B </span>","children":null,"spread":false},{"title":"project.properties <span style='color:#111;'> 563B </span>","children":null,"spread":false},{"title":"README.md <span style='color:#111;'> 392B </span>","children":null,"spread":false},{"title":"AndroidManifest.xml <span style='color:#111;'> 1.14KB </span>","children":null,"spread":false},{"title":"libs","children":[{"title":"android-support-v4.jar <span style='color:#111;'> 612.87KB </span>","children":null,"spread":false}],"spread":true}],"spread":true}]

评论信息

  • h768927887 :
    可以使用,有参考价值
    2019-07-26
  • xqc0 :
    和其它的例子没有太多差别。
    2019-03-15
  • aawsrayg :
    很好,解决了我的问题,谢谢楼主
    2018-07-24
  • zekrom- :
    用来偷拍的
    2018-07-14
  • renxuetao :
    可以使用,感谢分享
    2018-07-04

免责申明

【只为小站】的资源来自网友分享,仅供学习研究,请务必在下载后24小时内给予删除,不得用于其他任何用途,否则后果自负。基于互联网的特殊性,【只为小站】 无法对用户传输的作品、信息、内容的权属或合法性、合规性、真实性、科学性、完整权、有效性等进行实质审查;无论 【只为小站】 经营者是否已进行审查,用户均应自行承担因其传输的作品、信息、内容而可能或已经产生的侵权或权属纠纷等法律责任。
本站所有资源不代表本站的观点或立场,基于网友分享,根据中国法律《信息网络传播权保护条例》第二十二条之规定,若资源存在侵权或相关问题请联系本站客服人员,zhiweidada#qq.com,请把#换成@,本站将给予最大的支持与配合,做到及时反馈和处理。关于更多版权及免责申明参见 版权及免责申明