Did you try
myByteArray.position = 0
before reading it ?

You can try to use a Loader.loadBytes to instantiate a Bitmap (it uses a loader but it takes no time).

Do you load the picture before storing the bytes?
If it is helping, I built a loader that is storing bytes for a cache system and use Loader.loadBytes to instantiate the Bitmap:
http://www.soundstep.com/blog/downloads/somaloader/

To be sure your ByteArray is compressed, you can:
bytes.position = 0;
var compressed:uint = bytes.readUnsignedByte();
if (compressed == 0x43) trace("ByteArray is compressed!")

Little tips if you want to test, instead of using setPixels to "fill" your Bitmap, using graphics.beginBitmapFill seems quicker and less CPU intensive (test it, I'm not 100% sure).

Romu

Jiri wrote:
I came across some very weird behaviour and I can't seem to find an explanation for it. I am trying to write a class that will store compressed ByteArrays that are retreive throught the bitmapData.getPixels. Here is some testing code, that I wrote for the testing if a decompressed ByteArray can be parsed back into an Bitmapdata object.

It all works well if the uncompress/compress block is in the code. When i comment that code out, I get this error:

Could someone tell me what is happening here?


<error>
Error: Error #2030: End of file was encountered.
    at flash.display::BitmapData/setPixels()
    at GreyFilter_fla::MainTimeline/frame1()
</error>

<code>

import flash.display.Bitmap;
import flash.display.BitmapData;
import flash.geom.Point;
import flash.geom.Rectangle;

var destPoint:Point = new Point();
var source:Sprite = getChildByName('mcWalkArea') as Sprite;
var sourceRect:Rectangle = new Rectangle(0, 0, source.width, source.height);
var a:BitmapData = new BitmapData(sourceRect.width, sourceRect.height);

var storedMapData:ByteArray;

a.draw( source );
//create a black and white area.
a.threshold(a, sourceRect, destPoint , "!=", 0xFFFFFFFF , 0xFF000000 );
storedMapData = a.getPixels(sourceRect);

/* Try uncommenting this
trace(storedMapData.length);
storedMapData.compress()
trace(storedMapData.length);

storedMapData.uncompress()
trace(storedMapData.length);
*/

var tData:BitmapData = new BitmapData(sourceRect.width , sourceRect.height)
tData.setPixels( sourceRect , storedMapData );

var i:int = 0
while(i < source.width){
trace( tData.getPixel(i , 0 ) )
    i++
}

</code>

Jiri
_______________________________________________
Flashcoders mailing list
[email protected]
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders


_______________________________________________
Flashcoders mailing list
[email protected]
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Reply via email to