从子画面内部将图像从掩模下面保存下来

问题描述

| 我有一个精灵对象,该对象中已加载了自定义形状,该对象被用作蒙版,以便从加载了加载器对象的图像中切出自定义形状-loader(loada)和shape (线)对象都是sprite对象的子对象-我添加代码以从蒙版下保存图像,但是调用save函数时,不保存任何内容,也不会引发任何错误
function save(evt:MouseEvent):void{
    //Create random number from current date/time to name image created
    var imgID:Number= new Date().getTime()
    //Matrix to holder the area to be cropped
    var maskRect = loada.mask.getBounds(lines);
    //Matrix of image to be cropped
    var imgMatrix= loada.mask.transform.matrix;
    //Cropped image
    var myCroppedImage:Bitmap = cropImage(maskRect,imgMatrix,loada.mask.width,loada.mask.height,loada.mask );
    //Get new matrix of cropped image
    var m:Matrix = myCroppedImage.transform.matrix;
    var urlLoader:URLLoader = new URLLoader();
    //Set jpg quality of the image to be export 1-100
    var myEncoder:JPGEncoder = new JPGEncoder(80);
    //Create jpg to be exported
    var jpgSource:BitmapData = new BitmapData (loada.mask.width,loada.mask.height);
    jpgSource.draw(myCroppedImage,m);
    //Create byte array to hold jpg data
    var byteArray:ByteArray = myEncoder.encode(jpgSource);
    var header:URLRequestHeader = new URLRequestHeader(\"Content-type\",\"application/octet-stream\");
    trace(imgID);
    //Send image to the server to be saved
    var saveJPG:URLRequest = new URLRequest(\"save_image.PHP?r=\"+imgID);
    saveJPG.requestHeaders.push(header);
    saveJPG.method = URLRequestMethod.POST;
    saveJPG.data = byteArray; 
    trace(saveJPG);
}

//Crop image
function cropImage( rect,matrix,_width:Number,_height:Number,displayObject:displayObject):Bitmap {
    //Create cropped image
    var croppedBitmap:Bitmap = new Bitmap( new BitmapData( _width,_height ),PixelSnapping.ALWAYS,true );
    croppedBitmap.bitmapData.draw(displayObject,null,rect,true );
    return croppedBitmap;
}
    

解决方法

        从您在此处发布的内容来看,您似乎没有调用\“ load \”函数:
urlLoader.load(saveJPG);