简体   繁体   English

如何在AS3中使用iOS相机?

[英]How can you use the iOS camera in AS3?

Can you use the camera of an iOS device in an AS3 app? 您可以在AS3应用中使用iOS设备的相机吗? If so, how? 如果是这样,怎么办?

Yep it's really easy, there are many ways to access the camera in AS3. 是的,这真的很容易,在AS3中有很多访问摄像头的方法。

Firstly, the same way as you access the camera in normal AS3 applications: 首先,与在普通AS3应用程序中访问摄像机的方式相同:

var camera:Camera = Camera.getCamera();
var video=new Video();
video.attachCamera(camera);
this.addChild(video);

This will display the camera in the current display object. 这将在当前显示对象中显示摄像机。

You can also ask for images from the Camera roll using the CameraRoll class: 您还可以使用CameraRoll类从“相机”胶卷中请求图像:

import flash.media.CameraRoll;
var cameraRoll:CameraRoll = new CameraRoll();

if(CameraRoll.supportsBrowseForImage) 
{
    cameraRoll.addEventListener(MediaEvent.SELECT, imageSelected); 
    cameraRoll.addEventListener(Event.CANCEL, browseCancelled); 
    cameraRoll.addEventListener(ErrorEvent.ERROR, mediaError); 

    // Ask the user to select an image
    cameraRoll.browseForImage(); 
}

You can use the native "camera" application to take a photo: 您可以使用本机“相机”应用程序拍照:

import flash.media.CameraUI;

var cameraUI:CameraUI = new CameraUI();

if (CameraUI.isSupported ) 
{
    cameraUI.addEventListener(MediaEvent.COMPLETE, imageSelected); 
    cameraUI.addEventListener(Event.CANCEL, browseCancelled); 
    cameraUI.addEventListener(ErrorEvent.ERROR, mediaError); 

    cameraUI.launch(MediaType.IMAGE); 
}

Hope that points you in the right direction. 希望能为您指明正确的方向。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM