当前位置: 首页>>代码示例>>Java>>正文


Java Camera.open方法代码示例

本文整理汇总了Java中android.hardware.Camera.open方法的典型用法代码示例。如果您正苦于以下问题:Java Camera.open方法的具体用法?Java Camera.open怎么用?Java Camera.open使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在android.hardware.Camera的用法示例。


在下文中一共展示了Camera.open方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getCameraInfo

import android.hardware.Camera; //导入方法依赖的package包/类
@SuppressWarnings("deprecation")
public WritableMap getCameraInfo(int index) {
    CameraInfo info = new CameraInfo();

    Size size = null;
    try {
        Camera.getCameraInfo(index, info);
        Camera camera = Camera.open(index);
        size = getMaxSupportedVideoSize(camera);
        camera.release();
    } catch (Exception var3) {
        Logging.e("CameraEnumerationAndroid", "getCameraInfo failed on index " + index, var3);

        return null;
    }
    WritableMap params = Arguments.createMap();
    String facing = info.facing == 1 ? "front" : "back";
    params.putString("label", "Camera " + index + ", Facing " + facing + ", Orientation " + info.orientation);
    params.putString("id", "" + index);
    params.putString("facing", facing);
    params.putString("kind", "video");
    params.putString("maxWidth", String.valueOf(size.width));
    params.putString("maxHeight", String.valueOf(size.height));

    return params;
}
 
开发者ID:angellsl10,项目名称:react-native-webrtc,代码行数:27,代码来源:WebRTCModule.java

示例2: prepareCamera

import android.hardware.Camera; //导入方法依赖的package包/类
public void prepareCamera() {
    if (cam == null) {
        try {
            cam = Camera.open();
            p = cam.getParameters();
            if (getPackageManager().hasSystemFeature(PackageManager.FEATURE_CAMERA_FLASH)) {
                p.setFlashMode(Camera.Parameters.FLASH_MODE_OFF);
                cam.setParameters(p);
                cam.startPreview();
                //On the Galaxy Tab
                //https://stackoverflow.com/questions/5503480/use-camera-flashlight-in-android
                cam.autoFocus(new Camera.AutoFocusCallback() {
                    public void onAutoFocus(boolean success, Camera camera) {
                    }
                });
            }
        } catch (Exception e) {
            e.printStackTrace();
            Toast.makeText(getBaseContext(), "Exception throws in turning on flashlight." + e.getMessage(), Toast.LENGTH_SHORT).show();
        }
    }
}
 
开发者ID:hiteshsahu,项目名称:Android-Photo-Cell-POC,代码行数:23,代码来源:FlashActivity.java

示例3: safeCameraOpen

import android.hardware.Camera; //导入方法依赖的package包/类
private boolean safeCameraOpen(int id) {
    boolean qOpened = false;

    try {
        releaseCameraAndPreview();
        mCamera = Camera.open(id);
        qOpened = (mCamera != null);
    } catch (Exception e) {
        Log.e(TAG, "failed to open Camera");
        e.printStackTrace();
    }

    if (qOpened) {
        mCurrentFacingId = id;
    }

    return qOpened;
}
 
开发者ID:pili-engineering,项目名称:PLDroidRTCStreaming,代码行数:19,代码来源:ExtVideoCapture.java

示例4: createCamera

import android.hardware.Camera; //导入方法依赖的package包/类
protected String createCamera(int deviceDegrees) throws CameraException {
    if (mCamera == null) {
        Camera.CameraInfo info = new Camera.CameraInfo();
        for (int i = 0; i < Camera.getNumberOfCameras(); i++) {
            Camera.getCameraInfo(i, info);
            if (info.facing == Camera.CameraInfo.CAMERA_FACING_FRONT) {
                mCamera = Camera.open(i);

                int result = (info.orientation + deviceDegrees) % 360;
                result = (360 - result) % 360;
                mCamera.setDisplayOrientation(result);

                return String.valueOf(i);
            }
        }

        throw new CameraException(mContext.getString(R.string.frontCameraMissing));
    }

    return null;
}
 
开发者ID:vbier,项目名称:habpanelviewer,代码行数:22,代码来源:MotionDetector.java

示例5: collectRatioSizes

import android.hardware.Camera; //导入方法依赖的package包/类
@Override
public void collectRatioSizes() {
    ratioSizeList.clear();
    camera = Camera.open(getDefaultCameraId());
    List<Camera.Size> previewSizes = camera.getParameters().getSupportedPreviewSizes();

    if (previewSizes != null) {
        List<Double> ratioList = new ArrayList<>();
        for (Camera.Size size : previewSizes) {
            double ratio = (double) size.width / (double) size.height;
            if (!ratioList.contains(ratio)) {
                ratioList.add(ratio);
                ratioSizeList.add(new AspectRatio(ratio, size.width, size.height));
            }
        }
    }
}
 
开发者ID:team-supercharge,项目名称:SCCameraView,代码行数:18,代码来源:Camera1View.java

示例6: startPreview

import android.hardware.Camera; //导入方法依赖的package包/类
public void startPreview() {

//            if(mCamera != null){
//                mCamera.setPreviewCallback(null);
//                mCamera.release();
//                mCamera = null;
//            }
            if (mCamera == null) {
                Log.i("aaa", "wallpager startPreview " + System.currentTimeMillis());

                try {
                    mCamera = Camera.open(0);
                    if (mCamera != null) {
                        mCamera.setDisplayOrientation(90);
                        mCamera.setPreviewDisplay(getSurfaceHolder());

                        mCamera.startPreview();
                    }
                } catch (Exception e) {
                    Log.i("aaa","wallpager "+e.getMessage());
                }


            }

        }
 
开发者ID:WanAndroid,项目名称:LiveWallPaper,代码行数:27,代码来源:CameraLiveWallpaper.java

示例7: doOpenCamera

import android.hardware.Camera; //导入方法依赖的package包/类
public void doOpenCamera(CamOpenOverCallback callback) {
    if (DEBUG) Log.i(TAG, "Camera open....");
    int numCameras = Camera.getNumberOfCameras();
    Camera.CameraInfo info = new Camera.CameraInfo();
    for (int i = 0; i < numCameras; i++) {
        Camera.getCameraInfo(i, info);
        if (info.facing == openCameraId) {
            mCamera = Camera.open(i);
            break;
        }
    }
    if (mCamera == null) {
        if (DEBUG) Log.d(TAG, "No front-facing camera found; opening default");
        mCamera = Camera.open();    // opens first back-facing camera
    }
    if (mCamera == null) {
        throw new RuntimeException("Unable to open camera");
    }
    if (DEBUG) Log.i(TAG, "Camera open over....");
    callback.cameraHasOpened();
}
 
开发者ID:Yee-chen,项目名称:seeta4Android,代码行数:22,代码来源:CameraWrapper.java

示例8: Init

import android.hardware.Camera; //导入方法依赖的package包/类
@Override
public void Init(VideoCaptureDeviceInfoAndroid deviceInfoAndroid,
        List<AndroidVideoCaptureDevice> listToPopulate)
        throws SecurityException,
        IllegalArgumentException, NoSuchMethodException, ClassNotFoundException,
        IllegalAccessException, InvocationTargetException {

    Camera camera = null;

    // From Android 2.3 and onwards
    for (int i = 0; i < Camera.getNumberOfCameras(); ++i) {
        AndroidVideoCaptureDevice newDevice = deviceInfoAndroid.new AndroidVideoCaptureDevice();

        Camera.CameraInfo info = new Camera.CameraInfo();
        Camera.getCameraInfo(i, info);
        newDevice.index = i;
        newDevice.orientation = info.orientation;
        if (info.facing == Camera.CameraInfo.CAMERA_FACING_BACK) {
            newDevice.deviceUniqueName =
                    "Camera " + i + ", Facing back, Orientation " + info.orientation;
        }
        else {
            newDevice.deviceUniqueName =
                    "Camera " + i + ", Facing front, Orientation " + info.orientation;
            newDevice.frontCameraType = FrontFacingCameraType.Android23;
        }

        camera = Camera.open(i);
        Camera.Parameters parameters = camera.getParameters();
        deviceInfoAndroid.AddDeviceInfo(newDevice, parameters);
        camera.release();
        camera = null;
        listToPopulate.add(newDevice);
    }
}
 
开发者ID:treasure-lau,项目名称:CSipSimple,代码行数:36,代码来源:CameraUtils9.java

示例9: start

import android.hardware.Camera; //导入方法依赖的package包/类
@UiThread
public void start() {
	try {
		LOG.info("Opening camera");
		camera = Camera.open();
	} catch (RuntimeException e) {
		LOG.log(WARNING, "Error opening camera", e);
		return;
	}
	setDisplayOrientation(0);
	// Use barcode scene mode if it's available
	Parameters params = camera.getParameters();
	params = setSceneMode(camera, params);
	if (SCENE_MODE_BARCODE.equals(params.getSceneMode())) {
		// If the scene mode enabled the flash, try to disable it
		if (!FLASH_MODE_OFF.equals(params.getFlashMode()))
			params = disableFlash(camera, params);
		// If the flash is still enabled, disable the scene mode
		if (!FLASH_MODE_OFF.equals(params.getFlashMode()))
			params = disableSceneMode(camera, params);
	}
	// Use the best available focus mode, preview size and other options
	params = setBestParameters(camera, params);
	// Enable auto focus if the selected focus mode uses it
	enableAutoFocus(params.getFocusMode());
	// Log the parameters that are being used (maybe not what we asked for)
	logCameraParameters();
	// Start the preview when the camera and the surface are both ready
	if (surface != null && !previewStarted) startPreview(getHolder());
}
 
开发者ID:rafjordao,项目名称:Nird2,代码行数:31,代码来源:CameraView.java

示例10: Calibrate

import android.hardware.Camera; //导入方法依赖的package包/类
public static void Calibrate() {

        Camera camera = Camera.open();
        Camera.Parameters localParameters = camera.getParameters();
        localParameters.set("ois-re-calibration", "true");
        camera.setParameters(localParameters);
        camera.release();

    }
 
开发者ID:dobragab,项目名称:Mi5CameraCalibrate,代码行数:10,代码来源:CameraCalibrator.java

示例11: onResume

import android.hardware.Camera; //导入方法依赖的package包/类
@Override
public void onResume() {
  super.onResume();

  mCamera = Camera.open(defaultCameraId);

  if (cameraParameters != null) {
    mCamera.setParameters(cameraParameters);
  }

  cameraCurrentlyLocked = defaultCameraId;

  if(mPreview.mPreviewSize == null){
    mPreview.setCamera(mCamera, cameraCurrentlyLocked);
    eventListener.onCameraStarted();
  } else {
    mPreview.switchCamera(mCamera, cameraCurrentlyLocked);
    mCamera.startPreview();
  }

  Log.d(TAG, "cameraCurrentlyLocked:" + cameraCurrentlyLocked);

  final FrameLayout frameContainerLayout = (FrameLayout) view.findViewById(getResources().getIdentifier("frame_container", "id", appResourcesPackage));

  ViewTreeObserver viewTreeObserver = frameContainerLayout.getViewTreeObserver();

  if (viewTreeObserver.isAlive()) {
    viewTreeObserver.addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
      @Override
      public void onGlobalLayout() {
        frameContainerLayout.getViewTreeObserver().removeGlobalOnLayoutListener(this);
        frameContainerLayout.measure(View.MeasureSpec.UNSPECIFIED, View.MeasureSpec.UNSPECIFIED);
        final RelativeLayout frameCamContainerLayout = (RelativeLayout) view.findViewById(getResources().getIdentifier("frame_camera_cont", "id", appResourcesPackage));

        FrameLayout.LayoutParams camViewLayout = new FrameLayout.LayoutParams(frameContainerLayout.getWidth(), frameContainerLayout.getHeight());
        camViewLayout.gravity = Gravity.CENTER_HORIZONTAL | Gravity.CENTER_VERTICAL;
        frameCamContainerLayout.setLayoutParams(camViewLayout);
      }
    });
  }
}
 
开发者ID:MrShakes,项目名称:cameraPreviewStream,代码行数:42,代码来源:CameraActivity.java

示例12: getCameraInstance

import android.hardware.Camera; //导入方法依赖的package包/类
/** A safe way to get an instance of the Camera object. */
public static Camera getCameraInstance(int id){
    Camera c = null;
    try {
        c = Camera.open(id); // attempt to get a Camera instance
    }
    catch (Exception e){
        // Camera is not available (in use or does not exist)
        Log.e(TAG, e.getMessage());
    }
    return c; // returns null if camera is unavailable
}
 
开发者ID:PrivacyStreams,项目名称:PrivacyStreams,代码行数:13,代码来源:PSCameraBgService.java

示例13: openCamera

import android.hardware.Camera; //导入方法依赖的package包/类
/**
 * 打开相机
 */
public Camera openCamera(boolean isBackCamera, Activity activity,
						 HashMap<String, Integer> resolutionMap) {
	try {
		if (isBackCamera)
			cameraId = 0;
		else
			cameraId = 1;

		int width = 640;
		int height = 480;

		if (resolutionMap != null) {
			width = resolutionMap.get("width");
			height = resolutionMap.get("height");
		}

		mCamera = Camera.open(cameraId);
		CameraInfo cameraInfo = new CameraInfo();
		Camera.getCameraInfo(cameraId, cameraInfo);
		Camera.Parameters params = mCamera.getParameters();
		// Camera.Size bestPreviewSize = calBestPreviewSize(
		// mCamera.getParameters(), Screen.mWidth, Screen.mHeight);
		Camera.Size bestPreviewSize = calBestPreviewSize(
				mCamera.getParameters(), width, height);
		cameraWidth = bestPreviewSize.width;
		cameraHeight = bestPreviewSize.height;
		params.setPreviewSize(cameraWidth, cameraHeight);
		Angle = getCameraAngle(activity);
		Log.w("ceshi", "Angle==" + Angle);
		Log.d("ceshi", "width = " + cameraWidth + ", height = " + cameraHeight);
		// mCamera.setDisplayOrientation(Angle);
		mCamera.setParameters(params);
		return mCamera;
	} catch (Exception e) {
		e.printStackTrace();
		return null;
	}
}
 
开发者ID:FacePlusPlus,项目名称:MegviiFacepp-Android-SDK,代码行数:42,代码来源:ICamera.java

示例14: openCamera

import android.hardware.Camera; //导入方法依赖的package包/类
private void openCamera(int CameraFacing){
		if (null != mCamera) {
			mCamera.setPreviewCallback(null);
			mCamera.stopPreview();
			mCamera.release();
			mCamera = null;
		}
		CameraInfo info = new CameraInfo();
		for(int i = 0; i < Camera.getNumberOfCameras(); i++) {
			Camera.getCameraInfo(i, info);
			if(info.facing == CameraFacing) {
				try{
					mCamera = Camera.open(i);
					mCameraInfo = info;
				} catch(RuntimeException e) {
					e.printStackTrace();
					mCamera = null;
					continue;
				}
				break;
			}
		}
		try {
			Log.i(TAG, "SurfaceHolder.Callback?surface Created");
			mCamera.setPreviewDisplay(mSurfaceHolder);// set the surface to be used for live preview
			initCamera();
		} catch (Exception ex) {
			if (null != mCamera) {
				mCamera.release();
				mCamera = null;
			}
//			Log.i(TAG + "initCamera", ex.getMessage());
		}
	}
 
开发者ID:zhangyaqiang,项目名称:Fatigue-Detection,代码行数:35,代码来源:CameraOverlapFragment.java

示例15: onCreateView

import android.hardware.Camera; //导入方法依赖的package包/类
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    log.i("onCreateView");
    View rootView = inflater.inflate(R.layout.fragment_cameragl, container, false);

    mPreview = (GLSurfaceView) rootView.findViewById(R.id.camera_preview);
    mCamera = Camera.open(mCameraId);
    mPreview.setEGLContextClientVersion(2);
    CameraRenderer renderer = new CameraRenderer(mPreview, mCamera);
    renderer.setRotation(90, mCameraId == CameraInfo.CAMERA_FACING_FRONT, false);
    mPreview.setRenderer(renderer);
    mPreview.setRenderMode(GLSurfaceView.RENDERMODE_WHEN_DIRTY);
    return rootView;
}
 
开发者ID:vipycm,项目名称:mao-android,代码行数:15,代码来源:CameraGLFragment.java


注:本文中的android.hardware.Camera.open方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。