0

I'm trying to load a png file from the library into a bitmap data, but get an EOF error when trying to do so.

End of file was encountered. at flash.display::BitmapData/setPixels()

I've added comments with the values used in the code below.

var bitmapData_texture:BitmapData = new BitmapData(image.width, image.height, true, 0x0);
bitmapData_texture.draw(image);
var pixels:ByteArray = bitmapData_texture.getPixels(rect_bmp);
var bitmapData:BitmapData = new BitmapData(rect_bmp.width,rect_bmp.height,true,0x0);
trace("image width : "+image.width.toString());       //image width : 161
trace("image height: "+image.height.toString());      //image height: 171
trace("rect x      : "+rect_bmp.x.toString());        //rect x      : 0
trace("rect y      : "+rect_bmp.y.toString());        //rect y      : 0
trace("rect width  : "+rect_bmp.width.toString());    //rect width  : 161
trace("rect height : "+rect_bmp.height.toString());   //rect height : 2
trace("bmpd width  : "+bitmapData.width.toString());  //bmpd width  : 161
trace("bmpd height : "+bitmapData.height.toString()); //bmpd height : 2
bitmapData.setPixels(rect_bmp,pixels);
Nallath
  • 2,100
  • 20
  • 37
  • The easiest way to use a library picture as BitmapData is to convert it to bitmap and export it for ActionScript. This makes converting it unnecessary, but I understand it will create a larger swf. So now I have bitmapData_texture = new tile(0,0); where tile is a BitmapData class in the library. – David W. Allor Dec 15 '12 at 23:49
  • Actually, I'm still getting the same error, even when I access the BitmapData directly from the library and try to copy pixels into another bitmap, replacing the first line of my code above with bitmapData_texture = new tile(0,0) and removing the .draw(image) line. – David W. Allor Dec 15 '12 at 23:55

1 Answers1

1

I cant see anything wrong with the (posted) code. You could try tracing the byteArray info directly after getPixels call. might provide insight into the problem?

//should be 4 bytes for every pixel in byteArray; so 4x161x2 = 1288
trace(pixels.length);
//should be at start of byteArray; so 0
trace(pixels.position);
//if position=0, this should be same as length
trace(pixels.bytesAvailable);

Btw, i disagree with Nallaths comments - you can indeed load PNGs directly from the library (or via a url) without worrying about compression.