Welcome to the Official BlackBerry® Support Community Forums. This is your resource to discuss support topics with your peers, and learn from each other. New to the forum? Please visit the ‘Getting Started’ link below.
inside custom component

Adobe AIR Development

Reply
Regular Contributor
mahesh_DT
Posts: 65
Registered: 11-21-2011
My Carrier: developer

Conversion and displaying Byte array to bitmap, But how to display in sequence.

Hello Everyone,

I have a conflict with byte-array to bitmap conversion and to display the images. I have added the code for conversion as follows

private function showCapturedImage1(inty:int,byte:ByteArray):void
		{
			trace("Load image")
			trace("input type in fucntion of image"+inty);
			
			if(inty == 11)
			{
				loaderi1 = new Loader();
				 loaderi1.contentLoaderInfo.addEventListener(Event.COMPLETE,getBitmapData);
				loaderi1.loadBytes(byte);
				
			}
			
		}
		private function getBitmapData1(event:Event):void 
		{
			var BMPData:BitmapData;	
			var content:* = loaderi1.content;
			BMPData = new BitmapData(content.width,content.height);
var UIMatrix:Matrix = new Matrix();
			BMPData.draw(content,UIMatrix);								
			var bmp:Bitmap = new Bitmap(BMPData);   
			var img:Image = new Image();
			img.setImage(bmp);			
			img.x = 0;
			img.y = confirmFormY;
			img.scaleX = 0.5;
			img.scaleY = 0.5;
			img.cacheAsBitmap = true;
			confirmFormY = confirmFormY +img.height + 40;
			confirmationContainer.addChild(img);								
		}


if(i == 1)
{
  showCapturedImage1(Bytearray1)
}

if(i == 2)
{
  showCapturedImage1(Bytearray2)
}
if(i == 3)
{
  showCapturedImage1(Bytearray3)
}
if(i == 4)
{
  showCapturedImage1(Bytearray4)
}


 Upto now every thing is fine....And the images are also displaying correctly.

But the main problem is, Those images are not displaying in random positions like  1st- bytearray4,2nd- Bytearray3,3rd- Bytearray1, 4th- Bytearray2.And for next time it is displaying another random type....Can any one help me how to display all the images in the sequence i.e in the 1st to 4th order.

Any help will be appreciated,

Thank you in advance.

Please use plain text.
Developer
pyth
Posts: 137
Registered: 01-19-2011
My Carrier: Outer Space

Re: Conversion and displaying Byte array to bitmap, But how to display in sequence.

my guess would be that there's a race condition, meaning since you are loading the bytearrays with a loader, the program starts the loading for all of them, but it cannot tell which one is loaded first. and since you are using

 

confirmFormY = confirmFormY +img.height + 40;

of course it would put the image that was loaded completely first to the first position

 

so either you calculate the position some other way or you can only load image 2 when image 1 has finished. or you do everything in a completely different way

-----------------------------------------------------------------------
Keep the forum alive by clicking 'like', accepting solutions or saying 'thank you'
Please use plain text.
Regular Contributor
mahesh_DT
Posts: 65
Registered: 11-21-2011
My Carrier: developer

Conversion and displaying Byte array to bitmap, But how to display in sequence.

Thank You, Its the correct problem i am facing right now....Can you please suggest, like any other way to load an image from a byte array, I have tried a lot but the image itself is not loading.

Thank you in advance

Please use plain text.
Developer
pyth
Posts: 137
Registered: 01-19-2011
My Carrier: Outer Space

Re: Conversion and displaying Byte array to bitmap, But how to display in sequence.

do you have the bytearray beforehand or do you have to load it from somewhere? if it's the first case, this works for me, when i store the imgheight and imgwidth beforehand

var ba:ByteArray = ...//your bytearray
var _img:Image = new Image(); // 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 have to load it, i would say, store it in a list or an array. store the bytearrays as soon as they loaded (and it's index). when your list is full (all loaded), then sort your list. and when it is sorted, create your images from the bytearrays

-----------------------------------------------------------------------
Keep the forum alive by clicking 'like', accepting solutions or saying 'thank you'
Please use plain text.
Regular Contributor
mahesh_DT
Posts: 65
Registered: 11-21-2011
My Carrier: developer

Re: Conversion and displaying Byte array to bitmap, But how to display in sequence.

[ Edited ]

Thank you very much.

But a bit disapointment from my side, I have tried your code in this way...

var ba:ByteArray = labelDetails[f][l][8];                            "(Byte array)
var _img:Image = new Image(); // image
							
var w:int = 200;
var h:int = 200;
var bm:BitmapData = new BitmapData(w, h);
bm.setPixels(new Rectangle(0,0,w,h), ba);
_img.setImage(bm);
confcontainer.addChild(_img);
_img.x = 0;
_img.y = 650;

 But this giving the error "Error #2030: End of file was encountered.".Why will this come, and how to get out from this.

Please help.

Thanking you.

Please use plain text.
Developer
pyth
Posts: 137
Registered: 01-19-2011
My Carrier: Outer Space

Re: Conversion and displaying Byte array to bitmap, But how to display in sequence.

if you reach eof, i guess the width and height are wrong

-----------------------------------------------------------------------
Keep the forum alive by clicking 'like', accepting solutions or saying 'thank you'
Please use plain text.