保存和屏蔽摄像头仍然AS3 AIR IOS [英] Saving and masking webcam still AS3 AIR IOS

查看:256
本文介绍了保存和屏蔽摄像头仍然AS3 AIR IOS的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的目标是创建一个应用程序,用户可以拍摄他们的脸部图像,其中包括一个面部切口覆盖。我需要用户能够点击屏幕并让应用程序保存图片,使用相同的面部切口进行遮罩,然后将其保存到应用程序存储区。

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



例如:

  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

$ b 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);
//捕获图片BTN
var bitmapData:BitmapData = new BitmapData(1024,768);
bitmapData.draw(video);




$ p
$ b我很抱歉如果这是错误的做法就我个人而言,我还是相当新的ActionScript。如果您需要更多信息,我将很乐意提供。

解决方案

您只能通过 SharedObject 保存大约100kb的数据,所以你不能使用它。这意味着仅用于来保存应用程序设置,而且根据我的经验,AIR开发人员会忽略它,因为我们可以更好地控制文件系统。



我们有 文件 FileStream 类。这些类允许您直接读取和写入设备的磁盘,这是网络上不太可能的事情(用户是必须保存/打开的用户,不能自动完成)。



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

所以,下面是一个例子:

  //创建文件并将其解析为applicationStorageDirectory,它应该保存文件的位置
var f:File = File.applicationStorageDirectory.resolvePath(name.png);
//这可以防止iCloud备份。默认为false。苹果将​​拒绝任何使用此目录的大文件保存,这不会阻止iCloud备份。也可以使用cacheDirectory,尽管AIR的某些方面无法访问该目录
f.preventBackup = true;

//设置文件流
var fs:FileStream = new FileStream();
fs.open(f,FileMode.WRITE); //打开文件写入
fs.writeBytes(BYTE ARRAY HERE); //将一个字节数组写入文件
fs.close(); //关闭连接

这样可以保存到磁盘。要阅读,您可以在 READ 模式下打开FileStream。

  var fs :FileStream = new FileStream(); 
var output:ByteArray = new ByteArray();
fs.open(f,FileMode.READ); //打开文件写入
fs.readBytes(output); //将文件读入字节数组
fs.close(); //关闭连接

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

希望有帮助。


I am aiming to create an application where the user can take a picture of their face, which includes an overlay of a face cutout. I need the user to be able to click the screen and for the application to save the picture, mask it with the same face cutout, and then save it to the applications storage.

This is the first time using AIR on IOS with Actionscript3. I know there is a proper directory that you are supposed to save to on IOS however I am not aware of it. I have been saving other variables using SharedObjects...

E.g:

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

and then writing to it

so.data['variableID'] = aVariable;

This is how I access the front camera and display it. For some reason to display the whole video and not a narrow section of it, I add the video from the camera to a movieclip on the stage, 50% of the size of the stage.

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);

}

I apologize if this is the wrong way of going about this I am still fairly new to Actionscript as it is. If you need any more information I will be happy to provide.

解决方案

You can only save ~100kb of data via SharedObject, so you can't use that. It is meant solely to save application settings and, from my experience, is ignored by AIR devs because we have better control over the file system.

We have the File and FileStream classes. These classes allow you to read and write directly to and from the device's disk, something not quite possible on the web (the user is the one who has to save/open; can't be done automatically).

Before my example, I must stress that you should read the documentation. Adobe's LiveDocs are among the best language/SDK docs available and it will point out many things that my quick example on usage will not (such as in-depth discussion of each directory, how to write various types, etc)

So, here's an example:

// 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

So that will save to disk. To read, you open the FileStream in READ mode.

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

Again, please read the documentation. FileStream supports dozens of read and write methods of various types. You need to select the correct one for your situation (readBytes() and writeBytes() should work in all cases, though there are instances where you are should use a more specific method)

Hope that helps.

这篇关于保存和屏蔽摄像头仍然AS3 AIR IOS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆