Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

Troubleshooting
Research
Professional Opinions
Ask a Question
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE

troubleshooting Question

How do I capture a drawn shape as bitmap data using Flex and AIR?

Avatar of rarid122481
rarid122481 asked on
Adobe FlashApache Flex
4 Comments1 Solution824 ViewsLast Modified:
I am drawing a line. It's data type in Flex is UIComponent. I want to draw the shape, convert it to a bitmap, and then save it out as a png. How would I do this? I am currently getting an error on the mouse up event after creating the line that is suppose to capture the data as bitmap. Attached is my code with the error.
private var routeBitMapData:BitmapData;
			private var pngEncoder:PNGEncoder = new PNGEncoder();
			private var routeImageByteArray:ByteArray;
private var drawingShape:UIComponent=new UIComponent();
			private var maskShape:UIComponent=new UIComponent();


protected function createRouteState_enterStateHandler(event:FlexEvent):void
			{
				getAllRoutes();
				
				player_mc.x = 193;
				player_mc.y = 501;
				
				createRouteContainer.addElement(drawingShape);
				
				drawingShape.x = createRouteContainer.x;
				drawingShape.y = createRouteContainer.y;
				
				createRouteContainer.addElement(maskShape);
				maskShape.x = createRouteContainer.x;
				maskShape.y = createRouteContainer.y;
				
				drawMask();
				drawingShape.mask = maskShape; 
				
createRouteContainer.addEventListener(MouseEvent.ROLL_OUT, boardRollOut);
				createRouteContainer.addEventListener(MouseEvent.MOUSE_MOVE, boardMouseMove);
				createRouteContainer.addEventListener(MouseEvent.MOUSE_DOWN, boardMouseDown);
				createRouteContainer.addEventListener(MouseEvent.MOUSE_UP, boardMouseUp);
			}

private function boardMouseDown(e:MouseEvent):void
			{
				if(recordingRoute == true)
				{
					
					var curX:Number=drawingShape.mouseX;
					var curY:Number=drawingShape.mouseY;
					
					startX = curX;
					startY = curY;
					
					doDraw=true;
					
					xPosArray = [];
					yPosArray = [];
					
					currentColor=0xFFCC33;
					
					drawingShape.graphics.lineStyle(lineSize,currentColor);
					drawingShape.graphics.moveTo(curX,curY);
					
					
				}
			}

private function stopMouseTrack(event:TimerEvent):void
			{
				
				routeBitMapData = new BitmapData(drawingShape.width,drawingShape.height);
				routeBitMapData.draw(drawingShape); 
				
				routeImageByteArray = pngEncoder.encode(routeBitMapData);
				
			}

//this is my error
ArgumentError: Error #2015: Invalid BitmapData.
	at flash.display::BitmapData()

this is the line that causes the error:
routeBitMapData = new BitmapData(drawingShape.width,drawingShape.height);
ASKER CERTIFIED SOLUTION
Avatar of ActionScript_Helper
ActionScript_HelperFlag of India image

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Commented:
This problem has been solved!
Unlock 1 Answer and 4 Comments.
See Answers