2012-06-14 54 views
0

我有代碼在swf中創建舞臺的實時截圖。 之後,它保存爲JPEG格式。都好。只有Flash AS3從BitmapData copyPixels到jpeg屏幕截圖

,我不需要整個舞臺,我只需要一個缺口:

X,Y:357341 WIDT,高度:319483

我的代碼看起來是這樣的..

我在哪裏以及如何插入copypixels功能?

(我是一個新手的Flash,這樣下去容易對我:-)

function mouseReleaseSave(event:MouseEvent):void { 
import com.adobe.images.JPGEncoder; 
import flash.events.Event; 
import flash.net.URLLoader; 
import flash.net.URLRequestHeader; 
import flash.net.URLRequest; 

var jpgSource:BitmapData = new BitmapData(this.stage.stageWidth, this.stage.stageHeight); 
jpgSource.draw(this.stage); 
var jpgEncoder:JPGEncoder = new JPGEncoder(70); 
var jpgStream:ByteArray = jpgEncoder.encode(jpgSource); 

//set the request's header,method and data 
var header:URLRequestHeader = new URLRequestHeader("Content-type","application/octet-stream"); 
var loader:URLLoader = new URLLoader(); 
//sends jpg bytes to saveJPG.php script 
var myRequest:URLRequest = new URLRequest("saveJPG.php"); 
myRequest.requestHeaders.push(header); 
myRequest.method = URLRequestMethod.POST; 
myRequest.data = jpgStream; 
loader.load(myRequest); 
//fire complete event; 
loader.addEventListener(Event.COMPLETE,saved); 
function saved(e:Event){ 
    //trace the image file name 
    trace(loader.data); 
} 

}

回答

1

這應有助於:

var subArea:Rectangle = new Rectangle(0,0, 319,483); 
var newBmp:Bitmap = new BitmapData(319,483); 
var cutoutBmp:Bitmap = new Bitmap(newBmp, PixelSnapping.ALWAYS, true); 
cutoutBmp.bitmapData.draw(jpgSource, new Matrix(1, 0, 0, 1, -357, -341) , null, null, subArea, true); 
+0

當試圖使用從原蟲研究答案,我得到:「1067:將類型爲flash.display:BitmapData的值的隱式強制轉換爲不相關的類型flash.display:Bitmap。」 - 我錯過了什麼? – Engberg