I am using ActionScript 3.0
to capture image from users webcam ,It is working fine , however the problem is that the size of image is too big for my liking . Can I make it small , I tried changing coordinates of Bitmap Data
.
Can anybody suggest me the solution.
Thanks
Asked
Active
Viewed 4,109 times
0

Priyank Patel
- 6,898
- 11
- 58
- 88
-
You can use a transformation matrix as one of the arguments to `BitmapData.draw()` that will offer you the best quality of scaling. – shanethehat Mar 27 '12 at 11:53
-
http://stackoverflow.com/questions/964495/what-is-the-best-way-to-resize-a-bitmapdata-object – Jeremy D Mar 27 '12 at 15:44
1 Answers
3
When you capture the webcam you have to provide a matrix. This matrix can handle a rescaling.
var output:BitmapData = new BitmapData(camera.width * scaleFactor, camera.height * scaleFactor, false);
var matrix:Matrix = new Matrix();
matrix.scale(scaleFactor, scaleFactor);
output.draw(camera, matrix, null, null, null, true);
Sometimes the smoothing of this method is not really satisfying. A solution would be to use an intermediate:
var capture:BitmapData = new BitmapData(camera.width, camera.height, false);
capture.draw(camera);
//or with a newer compiler
//camera.drawToBitmapData(capture);
var intermediate:Bitmap = new Bitmap(capture);
intermediate.scaleX = intermediate.scaleY = scaleFactor;
output.draw(intermediate);
capture.dispose();
Prefer the first method if you are okay with the smoothing.

Kodiak
- 5,978
- 17
- 35
-
-
Indeed. The picture you will get in your output will have the same ratio as the webcam, not a 150:150 square. – Kodiak Mar 27 '12 at 13:06
-
Compile error for Flex 4.6: `BitmapData.draw(camera)`: `flash.media:Camera to an unrelated type flash.display:IBitmapDrawable.`; think you need to add `Video` in there – Grigorash Vasilij May 07 '14 at 07:18