0

I have the XML and raw bitmap data for a bitmap font. I want to take the raw data and set the pixels in the BitMapData so I can make my font.

Using haxe with the flash libraries.

Whenever I run my code I keep getting this error: Error: Error #2030: End of file was encountered. at flash.display::BitmapData/setPixels()

I am trying to use this technique in haxe but it fails: https://github.com/PrimaryFeather/Starling-Framework/blob/master/starling/src/starling/text/MiniBitmapFont.as

I really don't know what the issue is. I didn't include all of the bitmap data below because it is too big but there are 310 entries.

import flash.display.BitmapData;
import flash.geom.Rectangle;
import flash.utils.ByteArray;

...

private var BITMAP_WIDTH : Int = 128;
private var BITMAP_HEIGHT : Int = 64;

private var BITMAP_DATA : Array<Float> = [ 
        2027613533, 3413039936,  202148514, 2266925598, 4206886452, 4286853117,    2034947, 
        3202703399,  352977282, 2957757964, 3113652880, 2158068882, 1468709156, 2268063717, 
        2779310143, 2101025806, 3416509055, 4215794539, 3602168838, 1038056207, 1932393374 ];

...

public function get_texture() : BitmapFont {
        var bmpData : BitmapData = new BitmapData( BITMAP_WIDTH, BITMAP_HEIGHT );
        var bmpBytes : ByteArray = new ByteArray();
        var numBytes : Int = BITMAP_DATA.length;

        bmpBytes.position = 0;      
        for ( i in 0...numBytes ) {
            bmpBytes.writeUnsignedInt( Std.int( BITMAP_DATA[i] ) );
        }
        bmpBytes.position = 0;

        //bmpBytes.uncompress();
        bmpData.setPixels( new Rectangle( 0, 0, BITMAP_WIDTH, BITMAP_HEIGHT ), bmpBytes );

        return new BitmapFont().loadAngelCode( bmpData, XML_DATA );
}
user1261710
  • 2,539
  • 5
  • 41
  • 72

2 Answers2

0

Are you saying that BITMAP_DATA has 310 elements? It would need to have

BITMAP_WIDTH * BITMAP_HEIGHT = 8192

Your code raises other questions (Why is BITMAP_DATA a vector of floats, instead of an array of ints? Why not embed your image?), but that seems to be the source of underflow.

Michael Brewer-Davis
  • 14,018
  • 5
  • 37
  • 49
  • For some reason haxe would not accept it as an array of Ints! I am trying to reduce the memory footprint for fonts so I do not want to include the font pngs in my project. Why does bitmap data need 310 elements. I am trying to construct an image from code. – user1261710 Mar 11 '14 at 19:24
  • I am trying to use this technique in haxe but it fails: https://github.com/PrimaryFeather/Starling-Framework/blob/master/starling/src/starling/text/MiniBitmapFont.as – user1261710 Mar 11 '14 at 19:28
  • The WIDTH*HEIGHT is 8192. 128*64. – user1261710 Mar 11 '14 at 19:34
  • The uncompress in that method is critical--I haven't checked but I'm guessing the array given in your example decompresses to an 8192 byte array. – Michael Brewer-Davis Mar 11 '14 at 22:54
0

For haxe you need to install the format package: http://www.openfl.org/archive/community/general-discussion/what-if-format-compile-time-constant-about-flashutilsbytearray/

Also my problem was that I did not have the most up-to-date version of the OpenFL library installed on my machine.

user1261710
  • 2,539
  • 5
  • 41
  • 72