2010-03-04 60 views
0

當談到Flash時,我幾乎是最出色的菜鳥。Flash:BitmapData.draw(視頻)忽略視頻高度

這裏的動作(3):

// Here's the dumb-dumb: 
/*****************************************************************/ 
/*****************************************************************/ 
function captureImage(e:MouseEvent):void { 
    // The video still-image is captured and drawn...but at 320x240? Oh, and the real kicker is that it gets squeezed (resized), not cropped. 
    bitmapData.draw(video); 
} 
/*****************************************************************/ 
/*****************************************************************/ 


// Here's the other relevant code... 
/*****************************************************************/ 
var bandwidth:int = 0; 
var quality:int = 100; 

var myWidth:int = 320; // the width for camera, video, and bitmaps. 
var myHeight:int = 320; // the height for camera, video, and bitmaps. 

var cam:Camera = Camera.getCamera(); 
cam.setQuality(bandwidth, quality); 
cam.setMode(myWidth,myHeight,30,false); // (width, height, FPS, favorSize) 

var video:Video = new Video(); 
    video.attachCamera(cam); 
    video.x = 20; 
    video.y = 20; 
    // setting the video.width and video.height here makes the video appear in the desired aspect-ratio (1:1). If this is not set it defaults to 320x240. 
    video.width = myWidth; 
    video.height = myHeight; 
addChild(video); 

// 0xff0000 sets a red background just so I can see that the BitmapData "element" is 320x320 like it should be. 
var bitmapData:BitmapData = new BitmapData(myWidth, myHeight, false, 0xff0000); 

var bitmap:Bitmap = new Bitmap(bitmapData); 
    bitmap.x = 360; 
    bitmap.y = 20; 
    bitmap.width=myWidth; 
    bitmap.height=myHeight; 
addChild(bitmap); 


// capture_mc is my take-a-picture button. :-) 
capture_mc.buttonMode = true; 
capture_mc.addEventListener(MouseEvent.CLICK,captureImage); 

所以,我在這裏失蹤。我知道Flash的製造商並不強調所有圖像都應該以4:3的寬高比進行顯示,對吧? :o)

無論如何,感謝您幫助「n00b」。

p.s. Flash使用Ctrl + Y「重做」而不是Ctrl + Shift + Z(如Photoshop)這一事實讓我想要flash.events.destroy(flash),或者其他東西。

UPDATE

我想通了,如何從240視頻拉伸到320但在質量顯著減少這樣做。這裏是BOLD與更新的部件代碼:

var bitmapData:BitmapData = new BitmapData(myWidth,240, false, 0xff0000);

var bitmap:Bitmap = new Bitmap(bitmapData);
bitmap.x = 360;
bitmap.y = 20;
bitmap.width=myWidth;
bitmap.height=240;
bitmap.scaleY=1.333; // ADDED scaleY
addChild(bitmap);

所以我還是想找到最大化質量的解決方案。

回答

2

有人問我是否找到了解決方案,答案是肯定的。我只是從我的.fla複製+粘貼動作,所以我不會解釋下面的代碼(我實際上不記得什麼都做了)。很明顯,舞臺上有物體,所以你將無法使用即插即用......抱歉。隨意解釋評論中發生了什麼。 :-)

import flash.display.Bitmap; 
import flash.display.BitmapData; 
import com.adobe.images.PNGEncoder; 
// for javascript 
import flash.external.ExternalInterface; 

var snd:Sound = new camerasound(); //new sound instance for the "capture" button click 

var bandwidth:int = 0; // Maximum amount of bandwidth that the current outgoing video feed can use, in bytes per second. 
var quality:int = 100; // This value is 0-100 with 1 being the lowest quality. 

var myWidth:int = 240; 
var myHeight:int = 240; 

var hiderD:BitmapData = new BitmapData(myWidth+4,myHeight+4,false,0xffffff); 
var borderBox1:Bitmap = new Bitmap(hiderD); 
borderBox1.x = 22; 
borderBox1.y = 52; 
borderBox1.width=hiderD.width; 
borderBox1.height=hiderD.height; 

var borderBox2:Bitmap = new Bitmap(hiderD); 
borderBox2.x = 287; 
borderBox2.y = 52; 
borderBox2.width=hiderD.width; 
borderBox2.height=hiderD.height; 


addChild(borderBox1); 
addChild(borderBox2); 






var cam:Camera = Camera.getCamera(); 
cam.setQuality(bandwidth, quality); 
cam.setMode(320, myHeight, 30, true); // setMode(videoWidth, videoHeight, video fps, favor area) 

var video:Video = new Video(); 
video.attachCamera(cam); 
video.x = -500; 
video.y = -500; 
addChild(video); 

// display mode ONLY 
var video2:Video = new Video(); 
video2.attachCamera(cam); 
video2.x = -16; 
video2.y = 54; 
video2.width=320; 
video2.height=myHeight; 
var m:Shape = new Shape(); 
m.graphics.beginFill(0x0); 
m.graphics.drawRect(24, 54, 240, 240); // draw the mask 
m.graphics.endFill(); // end the fill 
video2.mask = m; 

addChild(video2); 


// used for sending 
var bitmapData:BitmapData = new BitmapData(320,myHeight,false,0xFF0000); 

// used for display 
var bitmapData2:BitmapData = new BitmapData(320,myHeight,false,0xAAAAAA); 
var bitmap2:Bitmap = new Bitmap(bitmapData2); 
bitmap2.x = 249; 
bitmap2.y = 54; 
bitmap2.width=320; 
bitmap2.height=myHeight; 
var m2:Shape = new Shape(); 
m2.graphics.beginFill(0x0); 
m2.graphics.drawRect(289, 54, 240, 240); // draw the mask 
m2.graphics.endFill(); // end the fill 
bitmap2.mask=m2; 
addChild(bitmap2); 

capture_mc.buttonMode = true; 
capture_mc.addEventListener(MouseEvent.CLICK,captureImage); 

function captureImage(e:MouseEvent):void { 
    snd.play(); 

    bitmapData2.draw(video); 

    bitmapData.draw(video); 

    warn.visible = false; 

    save_mc.buttonMode = true; 
    save_mc.addEventListener(MouseEvent.CLICK, onSaveJPG); 
    save_mc.alpha = 1; 
} 

save_mc.alpha = .5; 


function onSaveJPG(e:Event):void{ 

    saving.visible = true; 

    var byteArray:ByteArray = PNGEncoder.encode(bitmapData); 

    var header:URLRequestHeader = new URLRequestHeader("Content-type", "application/octet-stream"); 

    var saveJPG:URLRequest = new URLRequest("/utilities/saveImage.aspx"); 
    saveJPG.requestHeaders.push(header); 
    saveJPG.method = URLRequestMethod.POST; 
    saveJPG.data = byteArray; 

    var urlLoader:URLLoader = new URLLoader(); 
    urlLoader.addEventListener(Event.COMPLETE, sendComplete); 
    urlLoader.addEventListener(IOErrorEvent.IO_ERROR, onIOError); 
    urlLoader.dataFormat = URLLoaderDataFormat.VARIABLES; 
    urlLoader.load(saveJPG); 

    function sendComplete(event:Event):void{ 
     var loader:URLLoader = URLLoader(event.target); 
     ExternalInterface.call("updateImageInputWithFileName",loader.data.filename); 
     warn.visible = true; 
     saving.visible = false; 


     setTimeout(function(){warn.visible=false},10000); 
    } 
    function onIOError(event:Event):void{ 
     saving.visible = false; 
     ExternalInterface.call("error", "Error", "Could not save image." ,"There was a problem saving the image. You can try again or contact an administrator for assistance."); 
    } 
} 

warn.visible = false; 
saving.visible = false; 
-1

首先,按Ctrl + Shift + Z只是「撤消」Photoshop中的操作。 Ctrl + Y redoes :)

其次,視頻的高度和寬度取決於它所連接的相機。換句話說,如果你的相機被設置爲320×240,那麼它將保持這種狀態,除非你改變相機的高度和寬度。另外你犯了一個錯誤:它是

video.videoHeight = myHeight; 
video.videoWidth = myWidth; 

因此,這意味着你必須改變你的相機的高度和寬度。

+0

感謝。它看起來像'videoHeight'和'videoWidth'是隻讀的。此外,視頻DisplayObject以正確的寬高比(320x320或1:1)顯示實況網絡攝像頭視頻。它只是當我捕捉它仍然擠壓圖像到320x240。 – 2010-03-04 16:29:43

+0

從技術上講,Ctrl + Shift + Z撤銷撤銷。 :-) – 2010-03-04 16:30:02

-1

對於AS2應用矩陣變換:

import flash.display.BitmapData; 
import flash.geom.Matrix; 

capture_btn.onPress = function() { 
    var cameraBMP= new BitmapData(video.width, video.height); 
    var myMatrix:Matrix = new Matrix(); 
    myMatrix.scale(1.5, 1.5); 
    cameraBMP.draw(video,myMatrix); 
}