Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/flash/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Actionscript 3 遇到文件结尾。at flash.display::BitmapData/setPixels()_Actionscript 3_Flash_Actionscript_Eof_Flash Cs6 - Fatal编程技术网

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

Actionscript 3 遇到文件结尾。at flash.display::BitmapData/setPixels(),actionscript-3,flash,actionscript,eof,flash-cs6,Actionscript 3,Flash,Actionscript,Eof,Flash Cs6,我试图将png文件从库加载到位图数据中,但在尝试加载时出现EOF错误 遇到文件结尾。at flash.display::BitmapData/setPixels() 我已经用下面代码中使用的值添加了注释 var bitmapData_texture:BitmapData = new BitmapData(image.width, image.height, true, 0x0); bitmapData_texture.draw(image); var pixels:ByteArray = bit

我试图将png文件从库加载到位图数据中,但在尝试加载时出现EOF错误

遇到文件结尾。at 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);

我看不出(张贴的)代码有什么问题。您可以尝试在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的评论-您确实可以直接从库中加载PNG(或通过url加载),而无需担心压缩。

将库图片用作位图数据的最简单方法是将其转换为位图并导出用于ActionScript。这使得转换它变得不必要,但我知道它将创建一个更大的swf。现在我有了bitmapData_texture=new tile(0,0);其中tile是库中的BitmapData类。实际上,即使我直接从库中访问BitmapData并尝试将像素复制到另一个位图中,用BitmapData_texture=new tile(0,0)替换上面代码的第一行并删除.draw(image)行,我仍然会遇到相同的错误。pixels.position是1288,数组的末尾。我添加了像素。位置=0,错误消失了。谢谢