保存和屏蔽网络摄像头仍然是AS3 AIR IOS

时间:2013-12-16 22:29:32

标签: ios actionscript-3 flash air

我的目标是创建一个应用程序,用户可以在其中拍摄他们的脸部照片,其中包括脸部剪影的叠加。我需要用户能够单击屏幕并为应用程序保存图片,使用相同的面部剪切块将其屏蔽,然后将其保存到应用程序存储中。

这是第一次在带有Actionscript3的IOS上使用AIR。我知道你应该在IOS上保存一个正确的目录但是我不知道它。我一直在使用SharedObjects保存其他变量...

E.g:

var so:SharedObject = SharedObject.getLocal("applicationID");

然后写信给它

so.data['variableID'] = aVariable;

这是我访问前置摄像头并显示它的方法。由于某种原因显示整个视频而不是它的一小部分,我将摄像机中的视频添加到舞台上的动画片段,占舞台大小的50%。

import flash.media.Camera;
import flash.media.Video;
import flash.display.BitmapData;
import flash.utils.ByteArray;
import com.adobe.images.JPGEncoder


var camera:Camera = Camera.getCamera("1");
camera.setQuality(0,100);
camera.setMode(1024,768, 30, false);

var video:Video = new Video();
video.attachCamera(camera);


videoArea.addChild(video);


Multitouch.inputMode = MultitouchInputMode.TOUCH_POINT;
Capture_Picture_BTN.addEventListener(TouchEvent.TOUCH_TAP, savePicture);
function savePicture(event:TouchEvent):void
{
trace("Saving Picture");
//Capture Picture BTN
var bitmapData:BitmapData = new BitmapData(1024,768);
bitmapData.draw(video);

}

我很抱歉,如果这是错误的方式,我仍然是一个相当新的Actionscript。如果您需要更多信息,我将很乐意为您提供。

1 个答案:

答案 0 :(得分:0)

您只能通过SharedObject保存~100kb的数据,因此您无法使用它。它只是 来保存应用程序设置,根据我的经验,AIR开发人员会忽略它,因为我们可以更好地控制文件系统。

我们有FileFileStream个类。这些类允许您直接读取和写入设备的磁盘,这在Web上是不可能的(用户是必须保存/打开的人;无法自动完成)。

在我的例子之前,我必须强调你应该阅读文档。 Adobe的LiveDocs是最好的语言/ SDK文档之一,它会指出许多我不能使用的快速示例(例如对每个目录的深入讨论,如何编写各种类型等)

所以,这是一个例子:

// create the File and resolve it to the applicationStorageDirectory, which is where you should save files
var f:File = File.applicationStorageDirectory.resolvePath("name.png"); 
// this prevents iCloud backup. false by default. Apple will reject anything using this directory for large file saving that doesn't prevent iCloud backup. Can also use cacheDirectory, though certain aspects of AIR cannot access that directory
f.preventBackup = true; 

// set up the filestream
var fs:FileStream = new FileStream();
fs.open(f, FileMode.WRITE); //open file to write
fs.writeBytes( BYTE ARRAY HERE ); // writes a byte array to file
fs.close(); // close connection

这样就可以保存到磁盘上了。要阅读,请以READ模式打开FileStream。

var fs:FileStream = new FileStream();
var output:ByteArray = new ByteArray();
fs.open(f, FileMode.READ); //open file to write
fs.readBytes( output ); // reads the file into a byte array
fs.close(); // close connection

再次,请阅读文档。 FileStream支持各种类型的数十种读写方法。您需要为您的情况选择正确的一个(readBytes()writeBytes()应该适用于所有情况,尽管有些情况下您应该使用更具体的方法)

希望有所帮助。