Flex Bitmap

15 views
Skip to first unread message

suma...@gmail.com

unread,
Feb 5, 2008, 1:31:50 AM2/5/08
to Flex India Community
Hi guys,

I want to convert a canvas (which contains Image) to Bitmap and attach
that Bitmap to the application (mxml file).

I am trying to do this as below:

mainCanvas=new Canvas();
imgBitmap=new BitmapData(mainPanel.width, mainPanel.height);
imgBitmap.draw(mainPanel as Sprite);
var bmp:Bitmap=new Bitmap(imgBitmap);
mainCanvas.addChild(bmp)
addChild(mainCanvas);
mainCanvas.y=500;

I did this as AS3 for Flash CS3. In case of Flex components it is
showing following error:

ArgumentError: Error #2015: Invalid BitmapData.
at flash.display::BitmapData()

Please help me.

Thanks

Sumant

Vinod M Jacob

unread,
Feb 5, 2008, 3:35:50 AM2/5/08
to Flex India Community
Hi-

For the new BitmapData give some static value for width and height and
check whether its throwing any error?

Saravanan

unread,
Feb 5, 2008, 5:45:46 AM2/5/08
to Flex India Community
HI sumant,

Here the code for u..

<?xml version="1.0"?>
<!-- containers\navigators\VSLinkEffects.mxml -->
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
creationComplete="init();">
<mx:Script>
<![CDATA[
import mx.core.IUIComponent;
import mx.core.UIComponent;
import mx.containers.Canvas;
private function init(): void
{
var cn:Canvas = new Canvas();
cn.graphics.beginFill(0xFF0000,1);
cn.graphics.drawRect(0,0,100,100)
cn.graphics.endFill();
this.addChild(cn);
var bmpdata:BitmapData = new BitmapData(100,100);
bmpdata.draw(cn);
var spr:UIComponent = new UIComponent()
spr.y =200
spr.addChild(new Bitmap(bmpdata));
cn.addChild(spr);
}



]]>
</mx:Script>
</mx:Application>

suma...@gmail.com

unread,
Feb 5, 2008, 5:17:51 AM2/5/08
to Flex India Community
Hi Vinod

I had the same width and height problem.

Now its working.

thanks

Sumant

Bobbyinsane

unread,
Feb 5, 2008, 5:48:33 AM2/5/08
to Flex India Community
Hey

In draw method I dont think Type Casting (as Sprite) is required. Draw
method intakes IBitmapDrawable as an argument.
And I never used like that so I'm not sure of it.

Anyways try the sample code, same as urs, but haven't used Type
Casting

<?xml version="1.0"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
layout="absolute">
<mx:Script>
<![CDATA[
import mx.controls.Image;
import flash.display.Bitmap;

private function draw():void{

var color:BitmapData = new BitmapData(mySource.contentWidth,
mySource.contentHeight);

//Filling bitmap with target canvas, Here I dont think type casting
[as Sprite] is required.
color.draw(myCanvas);

var myImage:Image = new Image();
myImage.source = new Bitmap(color);
board.addChild(myImage);

}
]]>
</mx:Script>
<mx:Canvas x="10" y="10" id="myCanvas">
<mx:Image width="320" height="240" x="0" y="0" id="mySource"
source="test.jpg" click="draw()"/>
</mx:Canvas>

<mx:Canvas x="340" y="10" width="320" height="240" id="board"/>
</mx:Application>


Bobbyinsane
http://www.insanepixel.com



On Feb 5, 11:31 am, "suman...@gmail.com" <suman...@gmail.com> wrote:
Reply all
Reply to author
Forward
0 new messages