intoTHEwild
intoTHEwild

Reputation: 468

EOF error encountered while converting bytearray to bitmapdata

I am using

var bitmapdata:BitmapData=new BitmapData();
var pixels:Bytearray=new Bytearray();
pixels = rleDecodePixles();
bitmapdata.setPixels(bitmapdata.rect, pixels);

In the 4th line in the code above i am getting "Error: Error #2030: End of file was encountered." I checked the length of the pixels object which is 4 times the width*height of the rect object. Given that setPixels() functions reads unsigned int from bytearray and sets that value to pixels, I think it should work.

But I have no clue why this wont work. The pixels object is filled after RLE decoding of the data which i get from a server.

Is there any work around or any other method which I could try to use. The loader class wont work as the data that I get from the server is not in any of the recognized format.

Any help is greatly appreciated.

Shrikant

Thanks.

Upvotes: 0

Views: 6808

Answers (2)

Mexican Seafood
Mexican Seafood

Reputation: 504

You get the EOF error from ByteArray when you try to move its pointer beyond the last position available. When you fill your ByteArray, you actually move its pointer, so before you can do anything with it, you have to reset it's position.

Try :

var bitmapdata:BitmapData=new BitmapData();
var pixels:Bytearray=new Bytearray();
pixels = rleDecodePixles();
pixels.position = 0; // Reset ByteArray pointer
bitmapdata.setPixels(bitmapdata.rect, pixels);

Upvotes: 13

intoTHEwild
intoTHEwild

Reputation: 468

Also I just found out that the following code works:

bitmap.object.setPixels(bitmap.object.rect, bitmap.createPixels(width, height));

function creatPixels(width:int,height:int):Bytearray
{
   var result:Bytearray=new Bytearray();
    result.length=(width*height)<<2;
    return result;
}

But after i have modified the bytearray and then try to set the pixels it throws the aforementioned error. even more confused now.

Upvotes: 0

Related Questions