0

我在用

var bitmapdata:BitmapData=new BitmapData();
var pixels:Bytearray=new Bytearray();
pixels = rleDecodePixles();
bitmapdata.setPixels(bitmapdata.rect, pixels);

在上面代码的第 4 行中,我收到“错误:错误 #2030:遇到文件结尾”。我检查了像素对象的长度,它是矩形对象的宽度*高度的4 倍。鉴于setPixels()函数从 bytearray 读取 unsigned int 并将该值设置为像素,我认为它应该可以工作。

但我不知道为什么这不起作用。在对我从服务器获得的数据进行 RLE 解码后填充像素对象。

是否有任何解决方法或我可以尝试使用的任何其他方法。加载器类将无法工作,因为我从服务器获取的数据不是任何可识别的格式。

任何帮助是极大的赞赏。

什里坎特

谢谢。

4

2 回答 2

13

当您尝试将其指针移动到最后一个可用位置之外时,您会从 ByteArray 得到 EOF 错误。当您填充 ByteArray 时,实际上是在移动它的指针,因此在对它进行任何操作之前,您必须重置它的位置。

尝试 :

var bitmapdata:BitmapData=new BitmapData();
var pixels:Bytearray=new Bytearray();
pixels = rleDecodePixles();
pixels.position = 0; // Reset ByteArray pointer
bitmapdata.setPixels(bitmapdata.rect, pixels);
于 2010-03-24T23:35:32.137 回答
0

另外我刚刚发现以下代码有效:

bitmap.object.setPixels(bitmap.object.rect, bitmap.createPixels(width, height));

function creatPixels(width:int,height:int):Bytearray
{
   var result:Bytearray=new Bytearray();
    result.length=(width*height)<<2;
    return result;
}

但是在我修改了字节数组然后尝试设置像素后,它会引发上述错误。现在更迷茫了。

于 2010-03-19T05:56:23.373 回答