Stage snapshot saving with webcam view and image is working after compilation but not working once the executive file's location is changed
package
{import flash.display.DisplayObject;
import flash.display.IBitmapDrawable;
import flash.display.Stage;
import flash.net.FileFilter;
import com.adobe.images.JPGEncoder;
import com.adobe.images.PNGEncoder;
import flash.display.Bitmap;
import flash.display.BitmapData;
import flash.display.BlendMode;
import flash.display.Sprite;
import flash.events.Event;
import flash.filters.ColorMatrixFilter;
import flash.media.Camera;
import flash.media.Video;
import flash.display.Graphics;
import flash.events.MouseEvent;
import flash.display.Loader;
import flash.net.URLRequest;
import flash.net.URLRequestHeader;
import flash.net.URLRequestMethod;
import flash.net.URLLoader;
import flash.display.MovieClip;
import flash.display.DisplayObject;
import flash.geom.Matrix;
import flash.utils.ByteArray;
import flash.net.FileReference;
import flash.geom.Rectangle;
import flash.geom.Point;
public class Main extends Sprite
{
private var drawMatrix:Matrix;
private var Mask2:Loader = new Loader();
private var byteArray:ByteArray;
private var jpg:JPGEncoder = new JPGEncoder();
private var file:FileReference;
private var cam : Camera = Camera.getCamera();
private var vid : Video = new Video(640, 5开发者_高级运维00);
private var bitmapData:BitmapData = new BitmapData(vid.width, vid.height);
private var bitmap:Bitmap ;
private var fileReference:FileReference;
public function Main()
{
initTracking();
}
private function initTracking() : void
{
var camW : int = 640;
var camH : int = 500;
// Create the camera
cam.setMode(camW, camH, stage.frameRate);
// Create a video
vid.attachCamera(cam);
addChild(vid);
Mask2.load(new URLRequest("button.png"));
addChild(Mask2);
Mask2.y = 100;
Mask2.addEventListener(MouseEvent.CLICK, captureImage);
}
private function captureImage(event:MouseEvent):void {
bitmapData= new BitmapData(stage.width, stage.height)
bitmapData.draw(stage, new Matrix());
var bitmapDataA: BitmapData = new BitmapData(300, 250);
bitmapDataA.copyPixels(bitmapData, new Rectangle(360, 20, 620, 540), new Point(0, 0));
bitmap= new Bitmap(bitmapDataA);
addChild(bitmap);
bitmap.x = 0;
bitmap.y = 556;
bitmap.width = 105;
bitmap.height = 80;
}
}
}
Post the full class instead of snippits.
With what you posted all I can see is
//bitmapData is not defined
var byteArray:ByteArray = encoder.encode(bitmapData);
I have a feeling you are not accurate on the description of your issues.
精彩评论