• 大小: 628KB
    文件类型: .rar
    金币: 1
    下载: 0 次
    发布日期: 2021-06-08
  • 语言: Java
  • 标签: android  前摄像头  

资源简介

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

资源截图

代码片段和文件信息

/** Automatically generated file. DO NOT MODIFY */
package com.yxiaolv.camerasample;

public final class BuildConfig {
    public final static boolean DEBUG = true;
}

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----

    .......      7658  2014-02-24 00:55  res\drawable-hdpi\ic_launcher.png

    .......      3777  2014-02-24 00:55  res\drawable-mdpi\ic_launcher.png

    .......     12516  2014-02-24 00:55  res\drawable-xhdpi\ic_launcher.png

    .......     24777  2014-02-24 00:55  res\drawable-xxhdpi\ic_launcher.png

     文件       1350  2014-06-04 15:43  res\layout\activity_main.xml

     文件        439  2014-06-04 16:29  res\menu\main.xml

    .......       213  2014-02-24 00:55  res\values\dimens.xml

     文件        273  2014-06-04 16:30  res\values\strings.xml

    .......       680  2014-02-24 00:55  res\values\styles.xml

    .......       196  2014-02-24 00:55  res\values-sw600dp\dimens.xml

    .......       269  2014-02-24 00:55  res\values-sw720dp-land\dimens.xml

    .......       324  2014-02-24 00:55  res\values-v11\styles.xml

    .......       381  2014-02-24 00:55  res\values-v14\styles.xml

     文件       6712  2014-06-04 15:45  src\com\yxiaolv\camerasample\CameraActivity.java

     文件        475  2014-06-04 15:00  .classpath

     文件        848  2014-06-04 15:00  .project

     文件       1164  2014-06-04 15:45  AndroidManifest.xml

    .......     51394  2014-02-24 00:55  ic_launcher-web.png

    .......       781  2014-02-24 00:55  proguard-project.txt

     文件        563  2014-06-04 15:00  project.properties

    .......       392  2014-02-24 00:55  README.md

     文件        166  2014-06-04 17:10  gen\com\yxiaolv\camerasample\BuildConfig.java

     文件       2793  2014-06-04 17:10  gen\com\yxiaolv\camerasample\R.java

    .......    627582  2014-02-24 00:55  libs\android-support-v4.jar

     目录          0  2014-06-04 15:43  src\com\yxiaolv\camerasample

     目录          0  2014-06-04 17:10  gen\com\yxiaolv\camerasample

     目录          0  2014-06-04 15:44  src\com\yxiaolv

     目录          0  2014-06-04 17:10  gen\com\yxiaolv

     目录          0  2014-02-24 00:55  res\drawable-hdpi

     目录          0  2014-06-04 15:00  res\drawable-ldpi

............此处省略22个文件信息

评论

共有 条评论