Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Adobe AIR Development

Reply
Developer
Deepu_George_Jacob
Posts: 235
Registered: ‎12-13-2011
My Device: Curve 9380

How to convert Byte Array to bitmap??

Hai..,

             I need to convert byteArray to bitmap. my bytearray holds data for the images my code is..

 

var bmp:Bitmap = new Bitmap(smallImageByteArray as BitmapData);
bmp.opaqueBackground = 0xffffff;
bmp.x = 100;
bmp.y = 200;
addChild(bmp);

 

Anybody have the solution to this problem please help me

Thanks

Deepu

 

Developer
zezke
Posts: 1,004
Registered: ‎12-12-2010
My Device: Z10 (red Limited Edition)

Re: How to convert Byte Array to bitmap??

You could try something like this:

 

		public function Dummy()
		{
			var data:ByteArray;
			
			var loader:Loader = new Loader();
			loader.contentLoaderInfo.addEventListener(Event.COMPLETE, onLoaded);
			loader.loadBytes(data);
		}
		
		private function onLoaded(event:Event):void
		{
			var loader:Loader = event.target.loaders as Loader;
			var content:* = loader.content;
			var bitmapData:BitmapData = new BitmapData(content.width,content.height);
			bitmapData.draw(content, new Matrix);
		}

 

 I don't have the time test it right now though.

-------------------------------------------
BlackBerry Certified Builder for Native Application Development -- Proud member of the Belgian BlackBerry Developer group
Samples: Park in Ghent
Feeling generous? Nominate me for BB Elite member!
Developer
pyth
Posts: 508
Registered: ‎01-19-2011
My Device: My Trusty Red Plane

Re: How to convert Byte Array to bitmap??

[ Edited ]

you need to have width and height beforehand. you could store it when you store the bytearray. after that it's this

 

var ba:ByteArray = ...//your bytearray
var _img:Image = new Image(); //if you need an image

var w:int = imgwidth;
var h:int = imgheight;
var bm:BitmapData = new BitmapData(w, h);
bm.setPixels(new Rectangle(0,0,w,h), ba);
_img.setImage(bm); //if you want to

 

-----------------------------------------------------------------------
I'm a bird from outer space. But I'm not flappy o.o
Developer
Deepu_George_Jacob
Posts: 235
Registered: ‎12-13-2011
My Device: Curve 9380

Re: How to convert Byte Array to bitmap??

i got pixel error in this code
Developer
zezke
Posts: 1,004
Registered: ‎12-12-2010
My Device: Z10 (red Limited Edition)

Re: How to convert Byte Array to bitmap??

Pixel error?

-------------------------------------------
BlackBerry Certified Builder for Native Application Development -- Proud member of the Belgian BlackBerry Developer group
Samples: Park in Ghent
Feeling generous? Nominate me for BB Elite member!
Developer
Deepu_George_Jacob
Posts: 235
Registered: ‎12-13-2011
My Device: Curve 9380

Re: How to convert Byte Array to bitmap??

yes
Developer
zezke
Posts: 1,004
Registered: ‎12-12-2010
My Device: Z10 (red Limited Edition)

Re: How to convert Byte Array to bitmap??

Post your code, post the output... I am not a remote mind reader unfortunately.

-------------------------------------------
BlackBerry Certified Builder for Native Application Development -- Proud member of the Belgian BlackBerry Developer group
Samples: Park in Ghent
Feeling generous? Nominate me for BB Elite member!
Developer
pyth
Posts: 508
Registered: ‎01-19-2011
My Device: My Trusty Red Plane

Re: How to convert Byte Array to bitmap??

yeah, zezke is right. btw i think you must have done something wrong because I've been using that snippet for more than half a year already

-----------------------------------------------------------------------
I'm a bird from outer space. But I'm not flappy o.o
Developer
Deepu_George_Jacob
Posts: 235
Registered: ‎12-13-2011
My Device: Curve 9380

Re: How to convert Byte Array to bitmap??


var decoded:ByteArray = Base64.decodeToByteArray(sqlResutl.data[0].largeImage);
//trace(decoded);
/*var LWidth:Number = sqlResutl.data[0].largeImage_width;
var LHeight:Number = sqlResutl.data[0].largeImage_Height;

var rect:Rectangle = new Rectangle(0,0,LWidth,LHeight);
var newBmd:BitmapData = new BitmapData(rect.width,rect.height,true,0x000000);*/

/*var rect:Rectangle = new Rectangle(0,0,sqlResultForIndiaShelf.data[i].smallImage_width,sqlResultForIndiaShelf.data[i].smallImage_height);
var newBmd:BitmapData = new BitmapData(rect.width,rect.height,true,0x000000);
newBmd.setPixels(rect, ba);*/