2010-03-04 2 views
0

저는 플래시와 관련해 루키가 가장 루키입니다.플래시 : BitmapData.draw (비디오)가 비디오 높이를 무시합니다.

// 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); 

그래서, 내가 여기 실종 :

다음은 액션 스크립트 (3)입니다. Flash 제작자는 모든 이미지를 4 : 3 비율로 표시해야한다고 주장하지 않습니다. : o)

어쨌든 "n00b"를 도와 주셔서 감사합니다.

p.s. Flash가 Ctrl + Y를 사용하여 Ctrl + Shift + Z (예 : Photoshop) 대신 "다시 실행"을 사용하면 flash.events.destroy(flash) 또는 무엇인가를 원하게됩니다.

UPDATE : 나는 320 (240)에서 비디오를 스트레칭하지만 그 일에서 품질의 상당한 감소가하는 방법을 알아 냈

.

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;: 여기 BOLD에서 업데이트 된 부품 코드입니다 addChild(bitmap);

bitmap.scaleY=1.333; // ADDED scaleY
그래서 난 아직도 품질을 극대화 해결책을 찾기 위해 싶습니다.

답변

2

문제의 해결책을 찾았는지 묻는 질문에 대답이 예입니다. 저는 아래 코드를 설명하지 않으므로 (실제로 모든 것이 무엇인지 기억하지 못합니다) 내 .fla에서 actionscript를 복사 + 붙이는 것입니다. 그리고 분명히 무대에 물건이있어서 플러그 앤 플레이를 할 수 없습니다 ... 죄송합니다. 코멘트에 무슨 일이 일어나는지 설명해주십시오. :-)

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 다시 실행 :

둘째, 비디오의 높이와 너비는 연결된 카메라에 따라 다릅니다. 즉, 카메라가 320x240으로 설정된 경우 카메라의 높이와 너비를 변경하지 않는 한 카메라는 그대로 유지됩니다. 실수로 실수 한 경우 :

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

따라서 카메라의 높이와 너비를 변경해야합니다.

+0

감사합니다. 'videoHeight'와'videoWidth'는 읽기 전용입니다. 또한 비디오 DisplayObject는 올바른 종횡비 (320x320 또는 1 : 1)로 라이브 웹캠 비디오를 표시합니다.이미지를 320x240 크기로 압축 한 것입니다. –

+0

기술적으로 Ctrl + Shift + Z는 실행 취소를 실행 취소합니다. :-) –

-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); 
} 
관련 문제