Home Tutorials Forums Articles Blogs Movies Library Employment Press
Old 06-14-2012, 02:34 PM   #1
Senior Member
Join Date: Jan 2011
Posts: 135
Default Convert bitmap to byteArray

I have a bitmap I loaded in an air program and I want to convert it to a byteArray.

import flash.filesystem.File;
import flash.events.Event;
import flash.display.Loader;
import flash.utils.ByteArray;
import flash.display.BitmapData;
import flash.display.Bitmap;

var file:File = File.documentsDirectory;
file.addEventListener(Event.SELECT, handleSelectPicture);
file.browseForOpen("Select Picture");

function handleSelectPicture(event:Event):void
var loader:Loader = new Loader();
loader.contentLoaderInfo.addEventListener(Event.CO MPLETE, handleLoadPicture);
loader.load(new URLRequest(event.target.url));


function handleLoadPicture(event:Event):void
var loader:Loader = Loader(event.target.loader);
var image:Bitmap = Bitmap(loader.content);

PATurmel is offline   Reply With Quote
Old 06-14-2012, 02:51 PM   #2
Senior Member
Join Date: Oct 2008
Location: UK
Posts: 167

Look at bitmap.bitmapData.getPixels().

Robbus is offline   Reply With Quote
Old 06-14-2012, 04:37 PM   #3
Senior Member
henke37's Avatar
Join Date: Mar 2009
Location: Sweden
Posts: 10,886
Send a message via Skype™ to henke37

Which format do you want the data in the resulting ByteArray to have?
Signature: I wrote a pair of articles about the timeline.
henke37 is offline   Reply With Quote
Old 06-14-2012, 05:03 PM   #4
Super Moderator
ASWC's Avatar
Join Date: Dec 2007
Location: Greenville, SC
Posts: 6,528

Just load your bitmpa using a URLLoader with dataFormat set to
URLLoaderDataFormat.BINARY. You'll get directly your bitmap as a bytearray.
Super Duper!
ASWC is offline   Reply With Quote

Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

All times are GMT. The time now is 09:04 PM.

Follow actionscriptorg on Twitter


Powered by vBulletin® Version 3.8.5
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Ad Management plugin by RedTyger
Copyright 2000-2013 ActionScript.org. All Rights Reserved.
Your use of this site is subject to our Privacy Policy and Terms of Use.