Re: [Flashcoders] Strange behaviour ByteArray to BitmapData object

2009-03-16 Thread Jiri
Thank you. The position=0 seems to do the trick. I actually read over it 
in the documentation. RTFM should be RTFMW(ell) !! :)


> 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).

I dont actually want to render the bitmap. I make a black and white 
images of a hand drawn sprite, that acts as a walkarea. Every room has a 
different area and so i cache the ByteArray for every room. This 
'bumpmap' is used to check, with getPixel() if a clicked position is on 
the walkmap.
If I would render it to a graphics I will loose the getPixel() method 
for checking. Also when i use the Loader.loadBytes.


Or am i wrong?

Jiri



Romuald Quantin wrote:

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 #2030: End of file was encountered.
at flash.display::BitmapData/setPixels()
at GreyFilter_fla::MainTimeline/frame1()




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 , "!=", 0x , 0xFF00 );
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++
}



Jiri
___
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders



___
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders


___
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders


Re: [Flashcoders] Strange behaviour ByteArray to BitmapData object

2009-03-16 Thread Romuald Quantin

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 #2030: End of file was encountered.
at flash.display::BitmapData/setPixels()
at GreyFilter_fla::MainTimeline/frame1()




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 , "!=", 0x , 0xFF00 );
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++
}



Jiri
___
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders



___
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders


[Flashcoders] Strange behaviour ByteArray to BitmapData object

2009-03-16 Thread Jiri
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 #2030: End of file was encountered.
at flash.display::BitmapData/setPixels()
at GreyFilter_fla::MainTimeline/frame1()




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 , "!=", 0x , 0xFF00 );
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++
}



Jiri
___
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders