How To Specify Which Frame Of A Movieclip Gets Drawn With BitmapData.draw Method?
edit - heh, whoops - never mind. I am apparently an idiot. Is there a way to delete messages on this forum?--KenEdited: 04/30/2008 at 12:59:06 AM by asdfhabsaf
Adobe > ActionScript 3
Posted on: 04/30/2008 12:57:05 AM
View Complete Forum Thread with Replies
See Related Forum Messages: Follow the Links Below to View Complete Thread
AS2 - BitmapData Draw Method
Hi,
I need to take a snapshot of a mc using BitmapData. The problem I'm having is that the mcs content is centered and BitmapData.draw starts at x:0,y:0 - rendering only a quarter of the mc as a snapshot.
I'm using this code to copy pixels:
Code:
o:MovieClip // original mc
c:MovieClip // copy mc
btm = new BitmapData(o._width, o._height, true, 0xFFFFFF);
c.attachBitmap(btm, 0);
btm.draw(o);
Any suggestions on how to start .draw let's say x:-600, y:-500?
Thanks.
Question About The BitmapData Draw() Method
Example code:
var bitmap:BitmapData = new BitmapData(100, 100, true, 0x00ffffff)
bitmap.draw(sprite);
Is there a way to define the starting x,y point when drawing a sprites contents to a BitmapData object. I want to only copy a small section of the sprite, that is not the top left most corner.
Thanks for any help.
~squirt
AS3 - BitmapData Draw Method Problem
Hi!
I have this stupid class that tries to create a screen capture from of a region of the stage that it's below it's position. So to capture that region of the stage I'm passing this
ActionScript Code:
var coordsRect:Rectangle = this.getRect(oriBknd);
as Rectangle parameter to the BitmapData.draw method.
The problem is that when I start to drag the GlassWindow instance the rectangle region seems to work incorrectly and no screen is captured.
I can send you the fla if you want..
It just contains an image as background and this code:
ActionScript Code:
import com.polaco.window.*;
var win = new GlassWindow(100, 100);
win.x = 100;
win.y = 100;
this.addChild(win);
the class code:
ActionScript Code:
package com.polaco.window{
/**
A GlassWindow
@class GlassWindow
@package com.polaco.window
@author Federico "Polaco" Jakimowicz
*/
import flash.display.*;
import flash.events.Event;
import flash.events.MouseEvent;
import flash.display.Stage;
import flash.filters.*;
import flash.geom.Rectangle;
import flash.geom.Point;
import flash.geom.Matrix;
public class GlassWindow extends Sprite
{
private var backgroundData:BitmapData;
private var backGround:Bitmap;
private var backGroundMask:Bitmap;
private var oriBknd:Stage;
private var bkndWidth:int;
private var bkndHeight:int;
private var blurFilter:BlurFilter;
public function GlassWindow(w:int,h:int)
{
bkndWidth = w;
bkndHeight = h;
blurFilter = new BlurFilter(20, 20, BitmapFilterQuality.LOW);
cacheAsBitmap = false;
super();
addEventListener(Event.ADDED_TO_STAGE, onAddedToStage);
addEventListener(Event.REMOVED_FROM_STAGE, onRemovedFromStage);
useHandCursor=true;
}
private function onRemovedFromStage(e:Event):void{
removeEventListener(Event.ADDED_TO_STAGE, onAddedToStage);
}
private function onAddedToStage(e:Event):void{
oriBknd = stage;
if(backGround==null){
var transparent:Boolean = false;
var fillColor:uint = 0x000000;
backgroundData = new BitmapData(bkndWidth, bkndHeight, transparent , fillColor);
backGround = new Bitmap(backgroundData, "auto", false);
}
this.addChild(backGround);
addEventListener(Event.ENTER_FRAME, drawBackGround);
addEventListener(MouseEvent.MOUSE_DOWN, mouseDown);
addEventListener(MouseEvent.MOUSE_UP, mouseUp);
}
private function drawBackGround(e:Event):void{
trace("Height " + height);
var transparent:Boolean = false;
var fillColor:uint = 0x000000;
this.visible = false;
backgroundData.dispose();
backgroundData = new BitmapData(width, height, transparent , fillColor);
trace(this.getRect(oriBknd))
var coordsRect:Rectangle = this.getRect(oriBknd);
trace("this x " + this.x);
trace("this y " + this.y);
trace("coordsRect.bottomRight "+ coordsRect.bottomRight);
trace("stage y "+ oriBknd.y);
backgroundData.draw (oriBknd,new Matrix(),null,BlendMode.NORMAL,coordsRect,true);
var tRect:Rectangle = new Rectangle(0, 0, width, height);
var tPoint:Point = new Point(0, 0);
backgroundData.applyFilter(backgroundData,tRect,tPoint,blurFilter);
if(backGround!=null){
removeChild(backGround);
}
backGround = new Bitmap(backgroundData, "auto", false);
this.addChild(backGround);
this.visible = true;
}
private function mouseDown(e:Event):void{
startDrag();
}
private function mouseUp(e:Event):void{
stopDrag();
}
}//end class
}
thanks a lot,
It's 4:00AM I'll go to sleep.
Issues W/ Using Draw Method For BitmapData Instance
I'm just wondering if there are known issues with using the "draw" method of the BitmapData class...in my case, I'm loading in a SWF and converting it to a bitmap using the "draw" method and for some reason, it's drawing a different SWF than the one it's supposed to. It's like it is getting the SWF's confused and drawing the wrong ones to the wrong places?
has anyone ever had a problem with this? I don't think it's my logic, but it's always possible! My logic is working the way I think it should w/ this exception???
thx for the replies...here's an excerpt of my code:
Code:
//this code takes the loaded SWF (swfArray[i].content) and makes it into a Bitmap, then places the Bitmap into an empty
//movie clip (bitmapContainer) that has name and type values to record SWF name and type(category/class)//////////////////////////////////////////////////////////////////////////////////////////////////////
for(var i:int = 0; i < swfArray.length; i++) {
var swf:DisplayObject = swfArray[i].content;
var bd:BitmapData = new BitmapData(swf.width, swf.height); //scale down here if you want.
bd.draw(swf); //if you're scaling down, the optional second arg is a Matrix.
var swfPic:Bitmap = new Bitmap(bd);
swfPic.x = swfPic.y = 0;
swfPic.name = "swfPic";
var bitmapContainer:BitmapContainer = new BitmapContainer();
bitmapContainer.addChild(swfPic);
bitmapContainer.type = type;
bitmapContainer.swfName = swfNames[i];
bitmapContainer.positionInQueue = i;
bitmapContainerArray.push(bitmapContainer);
}
NOTE: this excerpt is contained in a loop, so it's performed multiple times if that helps clarify any issues!
Draw Method Of BitmapData Class Question
Hi guys
Thanks to guy's tutorial http://www.adobe.com/devnet/flash/ar...ge_api_03.html I have been experimenting with this way of manipulating images with code.
I just am stuck with the draw utilization within a class. The tutorial focusses on non class examples.
I have the following class
Code:
import flash.display.BitmapData;
import flash.geom.Matrix;
class Load extends MovieClip {
private var draw:Function;
private var parent:Object;
private var which:MovieClip;
private var myBitmap:BitmapData;
private var scale:Number;
private var scaleMatrix:Matrix;
private var scaledBitmap:BitmapData;
private var myOtherBitmap:BitmapData;
private var holder_mc:MovieClip;
function Load(parent, target, which) {
_parent = parent;
myBitmap = BitmapData.loadBitmap(which);
_parent.createEmptyMovieClip("target", 0);
_parent.target.attachBitmap(myBitmap, this.getNextHighestDepth());
}
public function fTransform(t) {
//trace(".."+typeof(this.parent.target));
//create a transformation matrix that will scale the bitmap
scaleMatrix = new Matrix();
scaleMatrix.scale(.25, .5);
_parent.scaledBitmap = new BitmapData(_parent.target._width, _parent.target._height, false, 0xFF000000);
///draw the bitmap and scale it using the specified transformation matrix
this.draw(_parent.target.myBitmap, scaleMatrix);
//this.draw(_parent.scaledBitmap, scaleMatrix);
//_parent.attachBitmap(_parent.scaledBitmap, 1);
}
}
I am simply trying to load a bitmap and scale it in half as a first step. I can see the bitmap on the stage at full scale and i know i need to apply the transform matrix to it with draw(); but as its inside the class i am getting confused as to the use.
I am trying to create 2 bitmaps one the original myBitmap then another called scaleBitmap I am thinking I can and should see them both.
Nice tutorial guy, wish that I could see a class example though.
And let me say that so many examples are still actionscript 1 style in the main help files for flash, utilisation in a class is often only a problem of scope but it would be nice to see that all the same.
BitmapData.draw Method Not Supported In Browser
Hi
I have developed a SWF file for live streaming the web cam and take snapshots in the receiving end . I am able to transmit and receive the video stream from web cam. I can also take snapshots from the receiving stream.But the snapshot works only when i run the swf file directly. But when i open the swf file in browser the snapshot is not working and i am not able to take the image from the video receiving.I am very new to flash.Please friends help me to solve this problem.Very urgent.
BitmapData::draw(BitmapData) Doesn't Seem To Support Alpha Channels
Hi all,
I have a BitmapData object with alpha channels, bm1, and would like to draw it into another BitmapData object, bm2. While I can draw bm1 into bm2, alpha channels do not seem to work. Here is some code to illustrate what I'm trying to do:
// create an all-green but semi-transparent BitmapData object (all alphas are set to 0x80 in the constructor)
var bm1:BitmapData = new BitmapData(100, 100, true, 0x8000FF00);
// create an all-white BitmapData object and display it
var bm2:BitmapData = new BitmapData(100, 100, true);
addChild(new Bitmap(bm2));
// draw bm1 into bm2 in the onTimer() callback function
bm2.draw(bm1);
I would expect bm2 to be light-green, because it's semi-transparent, but it's 100% green, i.e., 0xFF00FF00.
I already tried all blend modes, but blend modes didn't make a difference.
Any ideas?
Btw, what I'm trying to do is to extract an arbitrary collection of pixels (as opposed to a rectangle) from a bitmap (bm1) by copying it into another bitmap (bm2) and using alphas of 0x00 and 0xff to select the pixels to be extracted. Is there a better way to do this? (or any way for that matter? ;-)
Thanks!
-Bernd
Erasing Content Drawn With Draw API
I have a movieclip where I have drawn a bunch of stuff using the Draw API. How do I erase all the drawn stuff to clear the "slate"? Thanks in advance to anyone who can help me.
BitmapData Draw
I am using the BitmapData object and its draw method on a movieClip that has a textfield inside it. When I try to animate it after it has been drawn it is jumpy if animated at anything longer than a second, Sometimes even shorter than a second it gets jumpy. I have tried so many things to try and stop this but it just keeps happening. Has anyone had this problem and might know how to solve it. If I use just a solid it seems to work ok but with text it becomes jumpy. At 1 second animation sliding across the screen it jumps into place when it comes to its final position. I'm using the same Penner ease equations that I have always used.
Please anyone out there that can help, this is really doing my head in after 2 days of trying to get it to work.
Here is how i'm creating my bitmapData object.
Code:
private function createBitmapData(source, containerName:String):MovieClip{
var bitmapHolder:MovieClip=mcHolder.createEmptyMovieClip(containerName,mcHolder.getNextHighestDepth());
var bmpData = new BitmapData(source._width, source._height, true, 0x00FFFFFF);
bmpData.draw(source);
bitmapHolder.attachBitmap(bmpData, 1, "never", true);
return bitmapHolder;
}
BitmapData.draw()
I'm using the BitmapData class to perform some image manipulation which involves using the draw() method to draw a copy of a specified movieClip into the BitmapData object. This is working as expected, but it seems that to be able to copy something into a BitmapData object, that 'something' must already be on the stage.
So at the moment, I have to put the original image into a movieClip, hide it off stage somewhere, then pass that movieClip as the source for the BitmapData draw() method.
Is there any way to pass a linkage_id as the source for the draw() method, or is there any other way to copy a movieClip into Bitmapdata without the mc being on stage?
Cheers.
BitmapData.draw()
Is it possible to draw irregular piece of root for example a circle not square.
If I have a BitmapData 50x50 and want to draw in it a circle (corners leave blank or transparent), what should I do?
And one more question: how to replace whole BitmapData using draw() without creating new BitmapData object (when I want to draw transparent shapes they just add to existing BitmapData not replacing)
BitmapData.draw()
I have googeled, read the manuals but still don't get it.
I need proper example of how you draw some specific portion of the MovieClip into BitmapData.
I give function x:int, y:int, width:int, height:int parameters and it will return me BitmapData. Problem for me in this case is that i don't know how you position the clipping rectangle so that you could get little part from the middle of the MovieClip.
I have written this code:
Code:
public function getBitmapData(x:int, y:int, width:int, height:int):Bitmap{
var cutArea:Rectangle = new Rectangle(x,y,width,height);
var bitmapMapData = new BitmapData(width,height);
bitmapMapData.draw(mapMC,null,null,null,cutArea);
var bitmapMap = new Bitmap(bitmapMapData);
return bitmapMap;
}
where mapMC is movieClip. This function does not give me exact result what i expect but i guess people who have done it know what is the problem.
Thanks in advance!
BitmapData.draw() Problem
I'm having a problem with the BitmapData.draw method. If I draw a non-rectangular shape into a MC and use the .draw method, it seems flash copies the stage color behind it too.
I decided to use a AlphaChannel but I can't get it to work.
I made a small example of my problem.
The area in the left top should be black but it gets the stage's color.
*Note: the first line gets corrupted in this post :rolleyes
Code:
var DrawSpace:MovieClip = _root.createEmptyMovieClip(_root.getNextHighestDepth().toString(), _root.getNextHighestDepth());
function GetSquare(nx:Number, ny:Number, nw:Number, nh:Number, nc:Number, na:Number):flash.display.BitmapData {
DrawSpace.lineStyle(0, 0x000000, 0);
DrawSpace.beginFill(nc, na);
DrawSpace.moveTo(nx, ny);
DrawSpace.lineTo(nx + nw, ny);
DrawSpace.lineTo(nx + nw, ny + nh);
DrawSpace.lineTo(nx, ny + nh);
DrawSpace.lineTo(nx, ny);
DrawSpace.endFill()
var Square:flash.display.BitmapData = new flash.display.BitmapData(nw, nh, true, 0x00000000)
Square.draw(DrawSpace);
DrawSpace.clear();
return Square;
}
var WhiteSquare = GetSquare(0, 0, 200, 200, 0xFFFFFF, 100);
var MaskSquare = GetSquare(0, 0, 100, 100, 0xFF0000, 0);
var RootSquare = GetSquare(0, 0, 400, 400, 0x000000, 100);
_root.attachBitmap(RootSquare, _root.getNextHighestDepth());
WhiteSquare.copyChannel(MaskSquare, MaskSquare.rectangle, new flash.geom.Point(0, 0), 8, 8)
RootSquare.merge(WhiteSquare, WhiteSquare.rectangle, new flash.geom.Point(0, 0), 256, 256, 256, 256);
Loading A Swf Then Use BitmapData.draw()
I am trying to save a loaded swf as a BitmapData object. Ofcourse this swf is not animated, it just contains an icon or picture. When using the BitmapData.draw() method this does not seem to work, altough this works when i use it on any other mc wich isn't externally loaded. Is this just not possible ?
thnx
[F8] Bitmapdata.draw() Question
Hey all. I'm trying to draw the bitmap of an object once it has several objects attached inside. The problem is, if I put the object near the top of the movieclip and it spills above the line x=0, the image gets cut off. I am currently using something like this:
Code:
cellH = temp._height * secH;
cellW = temp._width * secW;
screen = new BitmapData(cellW, cellH, true, 0);
screen.draw(tempCell, new Matrix(), null);
lastCell.attachBitmap(screen, depth(lastCell));
Where temp is a clip attached just I can get measurement of it's width/height at run time, secH/secW is how large the gridded area I'm covering with the image is. Basically it just fetches dimensions for the bitmapdata screen. It works fine, and copys the mc, but as I described above, anything below y=0 or x=0 is cut off because screen is drawn from an x/y of (0, 0) in the target clip tempCell. Is there some way that I can get the screen moved up a bit (like 30 pixels) so I can copy the whole movieclip?
Problem In Using BitmapData.draw
when i use BitmapData.draw,and output what i get from the draw method,the text 's color display error(is white not black).I want to know why,and how can i fix it.
Thanks!
Download the files
the codes:
Quote:
//start
import flash.display.BitmapData;
import flash.geom.Rectangle;
import flash.geom.Matrix;
import flash.geom.ColorTransform;
var myBitmapData:BitmapData = new BitmapData(200, 200, false, 0xCCCCCCCC);
liumt_mc.createEmptyMovieClip("text_mc",liumt_mc.g etNextHighestDepth());
liumt_mc.text_mc.createTextField("text_txt",0,0,0, 150,20);
liumt_mc.text_mc.text_txt.text="the text's color is BLACK";
var myMatrix:Matrix = new Matrix();
var translateMatrix:Matrix = new Matrix();
var myColorTransform:ColorTransform = new ColorTransform(1, 1, 1, 1, 0, 0, 0, 0);
var blendMode:String = "normal";
var myRectangle:Rectangle = new Rectangle(0, 0, 200, 200);
var smooth:Boolean = true;
control_btn.onRelease = function() {
_root.outputClip(_root.liumt_mc)
};
function outputClip(who) {
//preloader visible
preloader._visible = true;
var pixels:Array = new Array();
//Create a new BitmapData
var snap = new BitmapData(who._width, who._height);
snap.draw(who, myMatrix, myColorTransform, blendMode, myRectangle, smooth);
var w:Number = snap.width, tmp;
var h:Number = snap.height;
//Build pixels array using an onEnterframe to avoid timeouts, capture a row per iteration, show a progressbar
var a:Number = 0;
this.onEnterFrame = function() {
for (var b = 0; b<=h; b++) {
tmp = snap.getPixel32(a, b).toString(16);
pixels.push(tmp.substr(1));
}
perc = int((a*100)/w);
preloader.perc.text = perc+" %";
preloader.barra._xscale = perc;
a++;
if (a>w) {
//Finish capturing
preloader._visible = false;
sendData(pixels, h, w);
//free memory
snap.dispose();
delete this.onEnterFrame;
}
};
}
function sendData(pixels:Array, h:Number, w:Number) {
//Create the LoadVars object and pass data to PHP script
var output:LoadVars = new LoadVars();
output.img = pixels.toString();
output.height = h;
output.width = w;
//The page (and this movie itself) should be in a server to work
pixels.toString();
output.send("show.php", "output", "POST");
//output.send("show.php", "output", "POST")
}
//end
Download the files
Problem With BitmapData Draw
I used a simple method to duplicate an mc but nothing shows up. I used the color just to make sure that the function was working. Anythoughts? I tried both draw and bitmapfill.
PHP Code:
function duplicateMovieClipImage(from, target){
var visuals = new flash.display.BitmapData(from._width, from._height,false,0xFF00FF00);
var transform:Matrix = new Matrix();
transform.scale(from._xscale/100,from._yscale/100)
visuals.draw(from,transform);
//target.attachBitmap(visuals, 1);
with(target){
beginBitmapFill(visuals, transform,false);
moveTo(0, 0);
lineTo(0, from._height);
lineTo(from._width, from._height);
lineTo(from._width, 0);
lineTo(0, 0);
}
}
Bitmapdata.draw() Not Working?
hi y'all,
i'm trying to render a Container object (with various stuff on it) to a bitmapdata object in flex. reason i'm doing this is that i need it to get onto a Plane for use in pv3d.
ActionScript Code:
//page is the Container object i'm talking about
var bmd:BitmapData = new BitmapData(_width, _height);
var material:BitmapMaterial = new BitmapMaterial(bmd);
bmd.draw(page);
material.smooth = true;
material.oneSide = false;
material.bitmap = bmd;
var page3d:Plane = new Plane(material, _width, _height, 8, 4);
the pv3d part seems to work, but instead of the contents of the Container it's all white... i've tried literally thousands of examples i found on the web, but nothing helps.. any ideas why this doesn't work?
BitmapData.draw() And Security
I am dynamically creating screen captures from flv files located in separate sub domains through the Bitmap Data Draw method. The problem is the illusion that flash calls security.
"When you call the BitmapData.draw() method with progressive video as the source parameter, the caller of BitmapData.draw() must either be from the same sandbox as the FLV file, or the server of the FLV file must have a policy file that grants permission to the domain of the calling SWF file. You can request that the policy file be downloaded by setting the checkPolicyFile property of the NetStream object to true."
Here is my first question. This seems to only apply to "progressive video". Is this yet another attempt to make us buy stream servers?
And now my second question.
Why is it that an end user can tap the flv files and draw freely as long as the embed object code references a cached version of the swf file but the remote swf file hosted on a separate sub domain in the same network needs to download a copy of the "policy file"?
BitmapData.draw() With Crossdomain
Hi,
I am trying to capture an FLV Frame with the bitmapdata.draw() function.
I works fine with same domain but don't with cross domain even with crossdomain.xml
I got a Security SandBox Violation
Here is the sample demo :
http://www.raprace.nl/forums/MMBBSevotest/Snapshot1.html
It should be considering the file http://loloviolo.com/crossdomain.xml
Here is the source
Thanks for your help.
LoLoVioLo
Attach Code
filename = "http://loloviolo.com:8080/MMBBS_Recorder/streams/video/5d989abef5ef9de6bfe584745bbf89e2.flv";
myConnThumb = new NetConnection();
myConnThumb.connect(null);
myNetStreamThumb = new NetStream(myConnThumb);
myCam.attachVideo(myNetStreamThumb);
myNetStreamThumb.play(filename);
var bitmap = new flash.display.BitmapData(160, 120, true, 0x00000000);
this.createEmptyMovieClip("copie", 2);
copie.attachBitmap(bitmap, 20, "auto", true);
copie._x = 200;
btn.onRelease = function() {
bitmap.draw(myCam);
};
BitmapData.draw And AllowDomain
This post in the Adobe documentation for BitmapData.draw sums up my situation:
quote:"If you control both domains in a cross-domain situation, you can use System.security.allowDomain to permit BitmapData.draw to work across domains. Say that domain A is the one calling BitmapData.draw, and domain B is the one from which the media was loaded. If the media from domain B is a SWF, it can call System.security.allowDomain("domainA.com"), and then the SWF from domain A can call BitmapData.draw."
However, using any of the Flashplayer nine players I can not reproduce this successfully. I have tried adding a request for crossdomain.xml on domain B by domain A, and have used System.security.allowDomain("*") in both movies for good measure. If I use the same movies on the same server the function performs.
Is it possible to draw the content of a swf from domain B loaded into a movie from domain A if you control both domains and both movies? Does anyone know of a working example of this? Is the quote from above valid? Are there some exceptions that I should know about?
Thanks for your time.
FMS 2 BitmapData.Draw() Security
The new audioSampleAccess and videoSampleAccess flags work great in FMS3 and the latest Flash player but I'm running into problems where CDNs have an older version of Media Server that doesn't support the tags or they are simply unwilling to tweak their server code to allow it. Is there any legitimate work-around to be able to access the Draw and raw audio functions? Thank you!
Bitmapdata.draw On Loader
Code:
var l=new Loader();
l.load(new URLRequest("test.jpg"));
var b = new BitmapData(400,300);
b.draw(l);
When I do addChild(l) it shows the image, so that is working properly.
What's wrong with this? The BitmapData keeps coming back as all-white.
BitmapData.draw( ClipRect )
Why oh why doesn't the BitmapData's draw (clipRect) parameter adjust the clipped rectangle's x,y to 0,0? Is there syntax for this that I'm missing? It seems logical that if I am going to selectively clip the drawn region with a rectangle, parameter, that I'd ONLY want that area drawn...
Though I also see how it could be useful to keep the original coordinates, but shouldn't that be an optional parameter tacked onto the draw method?
Code:
var rect:Rectangle = new Rectangle(100, 100, W, H);
var bitmapData:BitmapData = new BitmapData(W, H, false, 0xFFFFFF);
bitmapData.draw(DisplayObject, null, null, null, rect );
to compensate for this, I suppose you just have to do
Code:
var rect:Rectangle = new Rectangle(100, 100, W, H);
var bitmapData:BitmapData = new BitmapData(W+ 100, H+ 100, false, 0xFFFFFF);
bitmapData.draw(DisplayObject, null, null, null, rect );
and then in some other way adjust for that additional 100pixels when adding to the display list....
any have any better idea? I'm hoping I'm just not seeing something here.
BitmapData.draw() With Textfield
I am trying to convert text characters into bitmap and rendering them.
The quality of the bitmap rendered is poor.
The code is inline. The bitmap is rendered first and then the source textfield is placed underneath for
comparison. The quality becomes noticeably better as the font size is increased...
I appreciate any pointers into making the bitmap quality better at this font size.
thanks,
-jlogan
package {
import flash.display.Bitmap;
import flash.display.BitmapData;
import flash.display.Sprite;
import flash.text.TextField;
import flash.text.TextFormat;
import flash.text.TextFieldAutoSize;
public class Tbm extends Sprite
{
private var str:String = "abcdefghijklmnopqrstuvwxyz";
public function Tbm()
{
var fmt:TextFormat;
var bmd:BitmapData;
var bm:Bitmap;
var tf:TextField;
var len:int;
var dx:Number= 0;
fmt = new TextFormat();
fmt.font = "Arial";
fmt.size = 8;
len = str.length;
for (var i:int = 0; i < len; i++) {
tf = new TextField();
tf.text = str.charAt(i);
tf.setTextFormat (fmt);
tf.autoSize = TextFieldAutoSize.LEFT;
bmd = new BitmapData (tf.width, tf.height, true, 0);
bmd.draw (tf);
bm = new Bitmap (bmd);
bm.x+=dx;
bm.smoothing = true;
dx+= bm.width;
addChild (bm);
tf.x = bm.x;
tf.y = bm.height;
addChild (tf);
}
}
}
}
[FLEX] BitmapData.draw()
Hello,
I'm building a flickr application in flex at the moment but i keep getting sandbox errors when i invoke BitmapData.draw();.
After doing some google research i found that the proper policyfile needs to be loaded.
i do this using:
Code:
Security.loadPolicyFile("http://api.flickr.com/crossdomain.xml");
Now this still doesn't resolve the issues. Upon further research i found that i need to check the policy file first using checkPolicyFile = true;
But since i don't use loaders in flex and just set the source property to an URL, how would i go about implementing the checkPolicyFile ?
BitmapData.draw() Glitch
I have a Bitmap which I am scaling and then splicing using BitmapData.draw() along with a Matrix. Everything is working fine except for a strange glitch in the resultant Bitmap. There are gaps inbetween some of the divisions. Does this have sometihg to do with the scaling of the original Bitmap? Has anyone encountered this issue?
Problems With BitmapData.draw
Hi Everyone!
I'm new to this forum, and I really appreciate all you folks who stay up at night trying to solve other peoples mess! Thanks!
Now to the problem. I'm remaking the classic Solitaire game. When the player has finished the game all cards go crazy and fly around the screen. This is where my problem comes in.
I get the effect I want the only problem is that if i use a background image in my flash movie i cant see the effect, cause it draws at level0 (bmd.draw(this))! How do i get around this? Can i set the draw method to a specific level or to make it draw a displayObject that's at a certaint level?
Here's the code:
import fl.transitions.Tween;
import fl.transitions.easing.*;
import flash.display.*;
import flash.geom.*;
import flash.display.*;
var count:int = 13;
var orderCount:int = 0;
var topPosition:uint = this.numChildren - 1;
var bmd:BitmapData = new BitmapData(730, 580, true, 0xFFFFFF);
var order:Array = new Array("spades", "cloves", "hearts", "diamonds");
var bm:Bitmap = new Bitmap(bmd);
var timer:Timer = new Timer(500, 0);
var currentColor:Object;
var currentCard:String;
function randomNumber(startNum:Number, endNum:Number):Number
{
var lowNum:Number = startNum;
var highNum:Number = endNum;
return (Math.random() * (highNum - lowNum)) + lowNum;
}
function timerHandler(t:TimerEvent):void
{
currentColor = order[orderCount];
currentCard = currentColor.toString() + count;
var xTween:Tween = new Tween(this[currentCard], "x", Regular.easeOut, this[currentCard].x, -100, randomNumber(2, 3), true);
var yTween:Tween = new Tween(this[currentCard], "y", Bounce.easeOut, this[currentCard].y, 455, randomNumber(2, 4), true);
orderCount++;
if(orderCount > 3)
{
orderCount = 0;
count--;
}
if(count < 1)
{
trace("Timer cleared");
timer.removeEventListener("timer", timerHandler);
}
}
function loop(e:Event):void
{
bmd.draw(this);
}
this.addChild(bm);
timer.addEventListener("timer", timerHandler);
addEventListener(Event.ENTER_FRAME, loop);
timer.start();
The cards are objects on stage. For example:
"cloves12", "hearts5", "spades2", "diamonds13"
The problem is the bmd.draw(this) method. What can I use instead of "this" to draw at a certain level?
BitmapData Draw Memory Leak
hey guys,
this is my first post here and i really need your help !
here is my problem :
i create an empty movie clip, then add two children (2 movies clips in the library, each contains 28 frames, and each frame contains a bitmap image of size 140x105).
PHP Code:
var rootMovie:MovieClip = new MovieClip();
rootMovie.addChild(new board_coque());
rootMovie.addChild(new board_deck());
rootMovie.x = 100;
rootMovie.y= 100;
So my main movie contains only one frame with 2 layers, each layer containing 28 frames.
Then, for each 28 frame, i want to store it as a bitmap to draw it faster. So i loop in the 28 frames, for each frame, i loop in each layer of the movie clip, get the child and tell it to goto and stop to my current frame.
Then, i create a new BitmapData and draw the movie clip in it.
I also erase the bitmap just after...
PHP Code:
// for each frame
for(var j=1; j<=nbFrames; j++)
{
// for each layer
for(var i=0; i<nbChildren; i++)
{
MovieClip(rootMovie.getChildAt(i)).gotoAndStop(j);
}
// new bitmap
var newBitmapData:BitmapData = new BitmapData(140, 105, true, 0x00000000);
// DRAW
// comment this line and everything is ok !!!!!
newBitmapData.draw(rootMovie);
// we erase the bitmap
newBitmapData.dispose();
newBitmapData = null;
}
That's all guys ! then, you just have to check the memory before and after that piece of code, and you'll see that you've just lose 3MB...
And if you comment the draw line, it'll be ok !!!
I really don't understand where it comes from and it's pretty anoying in my case knowing that my main movie clip contains 20 layers of 300 frames each... so my memory increase about 300MB !!!
I've attached the source code of that.
Tell me if you have the same bug or if you have a way to solve it !
Thanks in advance for your help guys.
Mike.
BitmapData.draw() Becoming Incredibly Slow
I've been running into a problem with the BitmapData.draw() method becoming cripplingly slow sometimes. Basically what I'm doing is drawing vector layers on a map, then drawing those layers to a BitmapData that is displayed instead of the actual vector content to help with performance. Every time the map is panned or zoomed, the BitmapData takes a snapshot of the currently viewable area. The whole thing is difficult to explain concisely, but I'll take a crack at it:
-If anyone's familiar with it, I'm using Modest Maps to correctly draw and place my layers on Google Maps tiles.
-On top of the tiles sits a Sprite called container.
-Inside container are many various Sprites, let's say US state shapes.
-Whenever the underlying map is panned or zoomed, I loop over all the states and for each use Modest Maps methods to determine where to place the Sprite (within container) and how much to scale it.
-After that, a BitmapData (already established and sitting on the stage) is cleared with fillRect() and redrawn with container, clipping it to the visible map area, which has not changed.
I've skipped a couple of small details, but the important points are that container itself (the source of the BitmapData) never moves or scales and the area drawn never changes. Here's what goes on, though:
-I pan the map and the bitmap redraws with reasonable speed.
-I zoom in and the bitmap draws a bit more slowly.
-I pan again and the bitmap draws more quickly again.
-I zoom in again and the bitmap draws even more slowly.
-I pan again and it draws pretty quickly.
-I zoom in again and it draws more and more slowly, to the point where if I zoom in enough Flash just freaks out.
What baffles me is that the exact same process occurs for any of those actions, yet eventually there is a huge difference in the performance. (I have verified, by the way, that it is the bitmap draw that is slow, not the scale and location calculations.) Even stranger is that if I manage to zoom in far enough without killing Flash, it suddenly becomes fast again. It appears that after 5 or 6 zooms, it becomes fast and then again begins to slow when continuing to zoom.
It almost seems as though after zooming in it tries to draw the entire area of container rather than just the visible area, but as I said the same processes occur whether panning or zooming, and furthermore everything I've checked in traces or debugging indicates that it's all happening correctly.
Sorry if that's not particularly clear. I'd love to post my actual code, but it's a large project requiring tons of files, and it's unreleased client work that contract would forbid me from showing around yet anyway. If anyone thinks they have an idea of what the issue is, I can try to provide more details. For what it's worth: lock/unlock, making the bitmap invisible, and not adding the bitmap to the display list have had no significant effect.
Thanks!
BitmapData.draw(source:Object, ... );
hi all,
In the AS Dictionary, the BitmapData.draw method says it accepts a `source` for the first argument. Most examples show a MovieClip being passed for this argument, however, it is typed as Object. Does this mean BitmapData can be passed aswell? If so, does anyone know how this will affect the outcome of the rendering?
Cheers.
BitmapData.draw And ClipRectangle Param
Hi all,
I'm currently loading in an image, it is quite large, and I'm trying to split up the image into different parts.
when I'm drawing the area into a BitmapData Object, it has a param for clipping an area. The problem here is that the image will not show up after all is said and done. Am I right to assume that when you clip an image, the x,y coord of the clipped image moves to Point(0, 0) in the new BitmapData Object? or do I have to reposition it?
If so, how would I go about doing that?
stripped down example...
ActionScript Code:
// import all necessary classes here...
/* var source = Loaded external Image (MovieClip) */
var newClip = _root.createEmptyMovieClip("box", 10);
var image = new BitmapData( 100, 20, true, 0x00FF00FF);
var myRect = new Rectangle( 100, 100, 100, 20);
image.draw( source, null, null, null, myRect, true);
newClip.attachBitmap( image, 5, "auto", true);
Problem With Bitmapdata.draw And Swf Loaded
Hello actionscript people!
I have the following problem: bitmapdata.draw(movieclip) seems not to work if movieclip contains a clip with a swf file loaded inside. Even removing the clip with swf, bitmapdata.draw still does not work because some swf WAS loaded inside.
What is strange is that this is true we reading the file with flash player alone, but when reading the file embeded in html in firefox, there is not problem...
Is there a way to make it work when reading with flash player alone?
This is some examples of code
Code:
_level0.createEmptyMovieClip("font",-20)
var mcl:MovieClipLoader= new MovieClipLoader()
var listen:Object=new Object()
listen.onLoadInit=function(){
_level0.createEmptyMovieClip("essai",0)
_level0.createEmptyMovieClip("essai2",1)
rectangle.pl(_level0.essai2,700,500,0x0000AA,100)
var bit=new flash.display.BitmapData(Stage.width,Stage.height,false, 0x414141)
bit.draw(_level0)
_level0.essai2.removeMovieClip()
_level0.essai.attachBitmap(bit,0)
}
mcl.addListener(listen)
mcl.loadClip("picture.jpg",_level0.font)
Here a picture is loaded in _level0.font. This code works with flash player and firefox: displays a blue rectangle
Code:
_level0.createEmptyMovieClip("font",-20)
var mcl:MovieClipLoader= new MovieClipLoader()
var listen:Object=new Object()
listen.onLoadInit=function(){
_level0.createEmptyMovieClip("essai",0)
_level0.createEmptyMovieClip("essai2",1)
rectangle.pl(_level0.essai2,700,500,0x0000AA,100)
var bit=new flash.display.BitmapData(Stage.width,Stage.height,false, 0x414141)
bit.draw(_level0)
_level0.essai2.removeMovieClip()
_level0.essai.attachBitmap(bit,0)
}
mcl.addListener(listen)
mcl.loadClip("shared.swf",_level0.font)
Here a swf is loaded in _level0.font. This code doesn't work with flash player: no blue rectangle
Code:
_level0.createEmptyMovieClip("font",-20)
var mcl:MovieClipLoader= new MovieClipLoader()
var listen:Object=new Object()
listen.onLoadInit=function(){
_level0.font.removeMovieClip()
_level0.createEmptyMovieClip("essai",0)
_level0.createEmptyMovieClip("essai2",1)
rectangle.pl(_level0.essai2,700,500,0x0000AA,100)
var bit=new flash.display.BitmapData(Stage.width,Stage.height,false, 0x414141)
bit.draw(_level0)
_level0.essai2.removeMovieClip()
_level0.essai.attachBitmap(bit,0)
}
mcl.addListener(listen)
mcl.loadClip("shared.swf",_level0.font)
Here a swf is loaded in _level0.font. This code doesn't work with flash player, even if _level0.font is removed before bit.draw...
BitmapData.draw() - Simple Question.
Can someone explain to me how to get a "drawn" bitmap to be rendered at 0,0 when using a clip rectangle.
To simplify, say I have a 300x300 bitmap inside a movie clip with it's x,y registered to top left. I want to crop a 100x100 square area from the bottom right corner. My issue is the copied bitmap is drawn with it's x,y relative to the source image's x,y coordinates. So when it's added to the stage it's 200 pixels in on both the x & y axis.
Any help would be appreciated.
Code:
var myBitmapData:BitmapData = new BitmapData(300,300,false);
var clipArea:Rectangle = new Rectangle(200,200,100,100);
var myBitmap:Bitmap = new Bitmap(bmd);
myBitmapData.draw(targetMC,null,null,null,clipArea,true);
addChild(myBitmapData);
Bitmapdata Draw Memory Leak
hey guys,
this is my first post here and i really need your help !
here is my problem :
i create an empty movie clip, then add two children (2 movies clips in the library, each contains 28 frames, and each frame contains a bitmap image of size 140x105).
ActionScript Code:
var rootMovie:MovieClip = new MovieClip();
rootMovie.addChild(new board_coque());
rootMovie.addChild(new board_deck());
rootMovie.x = 100;
rootMovie.y= 100;
So my main movie contains only one frame with 2 layers, each layer containing 28 frames.
Then, for each 28 frame, i want to store it as a bitmap to draw it faster. So i loop in the 28 frames, for each frame, i loop in each layer of the movie clip, get the child and tell it to goto and stop to my current frame.
Then, i create a new BitmapData and draw the movie clip in it.
I also erase the bitmap just after...
ActionScript Code:
// for each frame
for(var j=1; j<=nbFrames; j++)
{
// for each layer
for(var i=0; i<nbChildren; i++)
{
MovieClip(rootMovie.getChildAt(i)).gotoAndStop(j);
}
// new bitmap
var newBitmapData:BitmapData = new BitmapData(140, 105, true, 0x00000000);
// DRAW
// comment this line and everything is ok !!!!!
newBitmapData.draw(rootMovie);
// we erase the bitmap
newBitmapData.dispose();
newBitmapData = null;
}
That's all guys ! then, you just have to check the memory before and after that piece of code, and you'll see that you've just lose 3MB...
And if you comment the draw line, it'll be ok !!!
I really don't understand where it comes from and it's pretty anoying in my case knowing that my main movie clip contains 20 layers of 300 frames each... so my memory increase about 300MB !!!
I've attached the source code of that.
Tell me if you have the same bug or if you have a way to solve it !
Thanks in advance for your help guys.
Mike.
BitmapData.draw: Moving The Reg Point?
Hi,
I've been using the bitmap draw method to record parts of movieclips, but I've hit a bit of a problem where I need to start the draw method from a certain point.
var bmdhf:BitmapData = new BitmapData(100, 100);
var bhf:Bitmap = new Bitmap(bmdhf);
bmdhf.draw(MovieClip(parent).area.front);
hf.addChild(bhf);
The problem is that when I do this, the Bitmap data starts the draw at 0,0 of that movieclip, when I need it to start drawing further in ie (starting at 100,100 then drawing to 200,200). Anyone know the way around this?
Cheers.
Having Trouble Using The BitmapData.draw() Function
Im having trouble using the BitmapData.draw() function... for some reason I can't draw a movieclip to the stage if the source (when untransformed) is larger than the size of the stage.
Anyone know how to get around this?
EDIT: I can draw them, but they are cropped to the stage size. Setting the clipRect property to larger than the stage size has no effect.
BitmapData Draw Vs CopyPixels + Transparency...
Hey,
Ive got a bitmap that im drawing everything to, and i was not sure if it was best to use MainBMP.copyPixels(myBmp, stuff...) or MainBMP.draw(myBmp, stuff...).
One uses rects/points to specify where to display whereas the other uses a matrix, which im guessing would allow me to include scaling and rotation things if needed...
Anyway im wondering which is faster if you were spamming it, also im loading a gif file with transparency, if i use Draw() it works fine and is transparent as i would expect, however copyPixels() doesnt display it as transparent and gives it a white background.
A) Which is faster statistically for mass calling?
B) Any rough idea why one is transparent one isnt?
Does BitmapData Draw What's Outside The Stage Area?
Quick question. I have a MC with some over sized content in it (2000,2000). The content is at x=-1000, y=-1000;
This MC sits on the stage and can be moved around. Sometimes it is at a negative X,Y and it extended past the stage width & height.
In the MC class I have a function:
ActionScript Code:
public function getBitmap():Bitmap
{
var bmpData:BitmapData = new BitmapData(grid.width, grid.height, false, 0xFFFF00);
bmpData.draw(this);
var bmp:Bitmap = new Bitmap(bmpData);
return bmp;
};
However, it seems to only capture the area visible on stage - from 0,0 to the width and height of the MC.
Anyone know if it's possible to capture the whole area of the MC?
Thanks
Bitmapdata Draw Memory Leak
hey guys,
this is my first post here and i really need your help !
here is my problem :
i create an empty movie clip, then add two children (2 movies clips in the library, each contains 28 frames, and each frame contains a bitmap image of size 140x105).
So my main movie contains only one frame with 2 layers, each layer containing 28 frames.
Then, for each 28 frame, i want to store it as a bitmap to draw it faster. So i loop in the 28 frames, for each frame, i loop in each layer of the movie clip, get the child and tell it to goto and stop to my current frame.
Then, i create a new BitmapData and draw the movie clip in it.
I also erase the bitmap just after...
That's all guys ! then, you just have to check the memory before and after that piece of code, and you'll see that you've just lose 3MB...
And if you comment the draw line, it'll be ok !!!
I really don't understand where it comes from and it's pretty anoying in my case knowing that my main movie clip contains 20 layers of 300 frames each... so my memory increase about 300MB !!!
I've attached the source code of that.
Tell me if you have the same bug or if you have a way to solve it !
Thanks in advance for your help guys.
Mike.
Attach Code
// we build a movie clip with 2 sub-movie clip in it
// this clip contains all the frames to be displayed
varrootMovie:MovieClip = new MovieClip();
rootMovie.addChild(new board_coque());
rootMovie.addChild(new board_deck());
rootMovie.x = 100;
rootMovie.y= 100;
varnbChildren:Number = rootMovie.numChildren;
varnbFrames:Number = MovieClip(rootMovie.getChildAt(0)).totalFrames;
varoutputStr:String = "";
varmemBefore:Number = flash.system.System.totalMemory / 1024;
outputStr += "Memory Before = " + memBefore + "kb
";
// we copy all the bitmaps in an array
for(var j=1; j<=nbFrames; j++)
{
// we go to the right frame
for(var i=0; i<nbChildren; i++)
{
MovieClip(rootMovie.getChildAt(i)).gotoAndStop(j);
}
// bitmap data creation
varnewBitmapData:BitmapData = new BitmapData(140, 105, true, 0x00000000);
// DRAW
// comment this line and everything is ok !!!!!
newBitmapData.draw(rootMovie);
// we erase the bitmap
newBitmapData.dispose();
newBitmapData = null;
}
// we remove all root movie children
while(rootMovie.numChildren > 0)
rootMovie.removeChildAt(0);
rootMovie = null;
varmemAfter:Number = flash.system.System.totalMemory / 1024;
vardMem:Number = memAfter - memBefore;
outputStr += "Memory After = " + memAfter + "kb
";
outputStr += "DELTA = " + dMem + "kb
";
outputStr += "DELTA per frame = " + String(dMem/nbFrames) + "kb
";
outputStr += "DELTA per frame per layer = " + String(dMem/nbFrames/nbChildren) + "kb
";
outputStr += "Theorical frame size (140x105 + alpha) = " + String(4*140*105/1024) + "kb
";
trace(outputStr);
this["output"].text = outputStr;
Load A Swf Then Use BitmapData.draw() Not Working ?
I am trying to load a external swf and then use the BitmapData.draw() method to draw the loaded swf to a bitmap. This does not seem to work. If I draw some lines into the loaded swf using the .lineTo() method and then use BitmapData.draw() i do see the lines that are made by this method, but not the content i put in the swf. Is it just not possible to do this ?
thnx
Wait For BitmapData.draw() To Finish
Is there any way to know when the draw method has finished it's work?
I'm kind of duplicating a movieclip into itself and applying a blur filter and a mask to create a reflection, but if i move or scale the MC before the draw method finishes then it doesn't create the reflection.
Any pointers to a solution will be apreciated.
Thanks in advanced.
BitmapData.draw() - Simple Question.
Can someone explain to me how to get a "drawn" bitmap to be rendered at 0,0 when using a clip rectangle.
To simplify, say I have a 300x300 bitmap inside a movie clip with it's x,y registered to top left. I want to crop a 100x100 square area from the bottom right corner. My issue is the copied bitmap is drawn with it's x,y relative to the source image's x,y coordinates. So when it's added to the stage it's 200 pixels in on both the x & y axis.
Any help would be appreciated.
Code:
var myBitmapData:BitmapData = new BitmapData(300,300,false);
var clipArea:Rectangle = new Rectangle(200,200,100,100);
var myBitmap:Bitmap = new Bitmap(bmd);
myBitmapData.draw(targetMC,null,null,null,clipArea,true);
addChild(myBitmapData);
Tiling An Image Using BitmapData.draw()
I'm loading in a large external swf image, and trying to cut it up into stage-sized chunks using BitmapData.draw() with a clipRect parameter, then draw those chunks back onto the stage, essentially producing the same-looking image as the swf.
However, the only thing that is drawing is the first chunk (the one that would appear at 0, 0). The rest are just coming out blank (but in the right spot on the grid).
Here's my code. Anyone know what the problem is?
Code:
var loader:Loader = new Loader();
loader.contentLoaderInfo.addEventListener(Event.COMPLETE, onLoadComplete);
loader.load(new URLRequest("midgroundBack.swf"));
var tileArray:Array = [];
function onLoadComplete(event:Event):void
{
var l:Loader = event.target.loader as Loader;
var stageWidth:Number = stage.stageWidth;
var stageHeight:Number = stage.stageHeight;
var nColumns:Number = Math.ceil(l.width / stageWidth);
var nRows:Number = Math.ceil(l.height / stageHeight);
trace("Column count: " + nColumns);
trace("Row count: " + nRows);
for (var i:int=0; i<nRows; i++)
{
tileArray[i] = [];
for (var j:int=0; j<nColumns; j++)
{
var rect:Rectangle = new Rectangle(j*stageHeight, i*stageWidth, stageWidth, stageHeight);
var bd:BitmapData = new BitmapData(stageWidth, stageHeight, true, 0x00000000);
bd.draw(l, new Matrix(), new ColorTransform(), "normal", rect);
var bitmap:Bitmap = new Bitmap(bd);
var sprite:Sprite = new Sprite();
sprite.addChild(bitmap);
tileArray[i][j] = sprite;
sprite.x = j * stageWidth;
sprite.y = i * stageHeight;
addChild(sprite);
trace("X: " + sprite.x + ", Y: " + sprite.y);
}
}
}
Essentially, I'm trying to get a grid of stage-sized images rather than one large image.
Thank you,
Eric Smith
|