0

我正在尝试将库中的 png 文件加载到位图数据中,但尝试这样做时会出现 EOF 错误。

遇到文件结尾。在 flash.display::BitmapData/setPixels()

我在下面的代码中使用了值添加了注释。

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);
4

1 回答 1

1

我看不出(发布的)代码有什么问题。您可以尝试在 getPixels 调用后直接跟踪 byteArray 信息。可以提供对问题的洞察力吗?

//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);

顺便说一句,我不同意 Nallaths 的评论——您确实可以直接从库(或通过 url)加载 PNG,而不用担心压缩。

于 2012-12-16T04:34:20.113 回答