如何在AS3 iOS中设计风格或降低相机视频的质量?

时间:2014-07-06 15:16:11

标签: ios actionscript-3 ipad

在iOS上的AS3中是否有办法用过滤器进行风格化或大幅降低iPad相机输出的质量以使其看起来高度抽象?此处的代码显示了当前它的带宽和质量设置非常低的工作方式。

import flash.display.Bitmap;
import flash.display.BitmapData;
import flash.display.MovieClip;
import flash.events.Event;
import flash.events.MouseEvent;
import flash.geom.Point;
import flash.geom.Rectangle;
import flash.media.Camera;
import flash.media.CameraPosition;
import flash.media.Video;

var camW: int = 1024;
var camH: int = 730;
var video: Video;

var rows: int = 7;
var cols: int = 9;
var pieceW: int = camW / cols;
var pieceH: int = camH / rows;
var pointArray: Array = new Array();

startCamera();

function startCamera() {
    var camera:Camera;
    camera = getCamera(CameraPosition.FRONT);
    camera.setMode(camW, camH, 30);
    camera.setQuality(10,2);
    video = new Video(camW, camH);
    video.attachCamera(camera);

    initpieces(); //chop video into pieces to create a jigsaw puzzle

    addEventListener(Event.ENTER_FRAME, updatepieces);//keep updating each pieces video
}

function initpieces(): void {
    for (var r: int = 0; r < rows; r++) {
        for (var c: int = 0; c < cols; c++) {
            var piece: MovieClip = new MovieClip();
            piece.name = "piece" + r + c;
            var p: Point = new Point(c * pieceW, r * pieceH);
            piece.x = c * (pieceW) + pieceW / 2;
            piece.y = r * (pieceH) + pieceH / 2;
            pointArray[piece.name] = p;

            var bmpd: BitmapData = new BitmapData(pieceW, pieceH);
            var bmp: Bitmap = new Bitmap(bmpd);
            bmp.name = "myBmp";

            piece.addChild(bmp);
            bmp.x = -pieceW / 2;
            bmp.y = -pieceH / 2

            addChild(piece);
        }
    }
}

function updatepieces(e: Event): void {
    var srcBmpd: BitmapData = new BitmapData(camW, camH);
    srcBmpd.draw(video);
    for (var r: int = 0; r < rows; r++) {
        for (var c: int = 0; c < cols; c++) {
            var b_mc: MovieClip = this.getChildByName("piece" + r + c) as MovieClip;
            var bmp: Bitmap = b_mc.getChildByName("myBmp") as Bitmap;
            var p: Point = pointArray[b_mc.name];

            bmp.bitmapData.copyPixels(srcBmpd, new Rectangle(p.x, p.y, pieceW, pieceH), new Point());
        }
    }
}

function getCamera(position: String): Camera {
    for (var i: uint = 0; i < Camera.names.length; ++i) {
        var cam: Camera = Camera.getCamera(String(i));
        if (cam.position == position) return cam;
    }
    return Camera.getCamera();
}

结果有点模糊,根本不是很抽象。

理想情况下,我希望逐渐提高质量,直到观众意识到图像来自他们自己的相机。

1 个答案:

答案 0 :(得分:0)

  

理想情况下,我希望逐渐提高质量,直到...

我没有测试你的代码,但是..你是否想要制作一个更长的(过渡时间)版本的效果?

你也可以尝试这个:(ps:使用计时器来更新myMoz.pixelSize = 10;

无论如何,您可以查看他们的源代码并获取您自己的BitmapData对象的想法......