0

我正在从 Flash 中的图像构建一个立方体。加载器加载图像的精灵图:

+----++----++----++----++----++----+
|frnt||rght||back||left||top ||bot |
|    ||    ||    ||    ||    ||    |
+----++----++----++----++----++----+

我得到的错误是:

错误 #2005:参数 0 的类型不正确。应该是类型 BitmapData。

在线front.draw(src, null, null, null, clip);(通过注释掉代码并且没有收到错误来确认)。但我不确定为什么。我定义 srcBitmapData, 和 atracesrc产生[object BitmapData]

private function loaderCompleteListener(e:Event):void
{
  log('Complete');
  var front:BitmapData,
    right:BitmapData,
    back:BitmapData,
    left:BitmapData,
    top:BitmapData,
    bottom:BitmapData,
    srcData:Bitmap,
    src:BitmapData,
    clip:Rectangle;

  try
  {
    srcData = this._imageLoader.content as Bitmap;
    src = srcData.bitmapData;
    front = new BitmapData(src.height, src.height, false, 0);
    right = new BitmapData(src.height, src.height, false, 0);
    back = new BitmapData(src.height, src.height, false, 0);
    left = new BitmapData(src.height, src.height, false, 0);
    top = new BitmapData(src.height, src.height, false, 0);
    bottom = new BitmapData(src.height, src.height, false, 0);
    clip = new Rectangle(0, 0, src.height, src.height);

    //This is the line that causes the error
    front.draw(src, null, null, null, clip); //<----
    clip.x += src.height;
    right.draw(src, null, null, null, clip);
    clip.x += src.height;
    back.draw(src, null, null, null, clip);
    clip.x += src.height;
    left.draw(src, null, null, null, clip);
    clip.x += src.height;
    top.draw(src, null, null, null, clip);
    clip.x += src.height;
    bottom.draw(src, null, null, null, clip);
  }
  catch ( e:Error )
  {
    log(e.message);
  }
}

我错过了什么?

编辑添加:

一种考虑可能是图像大小。我正在加载 1866×11196 的图像。我明天会测试,看看是否可以使用较小的图像。可能只是 Flash 无法处理超过一定大小的图像。

4

4 回答 4

2

bitmapdata 的最大宽度或长度为 8192,但如以下链接所述,不能同时使用两者。即总像素数不能超过 16,777,215 像素。

http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/display/BitmapData.html

于 2011-03-09T05:12:36.533 回答
2

正如 Chris 所指出的,对于任何 BitmapData,高度或宽度的内置最大值为 8192,因此您将无法原生使用宽度为 11196 的图像。

但是,您可以在此处找到解决方法,例如 BitmapDataUnlimited 类。

于 2011-03-09T11:49:39.383 回答
1

首先,我需要感谢@Chris、@EyeSeeEm、@Nathan Ostgard 引导我了解我收到错误的原因。我的期望是IOErrorEvent.IO_ERROR如果图像没有正确加载(至少对我来说这似乎是一个 IO 错误),但 Flash 显然认为这个错误还不够,这就是我收到虚假错误的原因。

正如大家所指出的,AS3 文档指定图像不能超过特定大小。

闪存播放器 9:

BitmapData 对象的最大宽度和最大高度为 2880 像素。

闪存播放器 10:

在 AIR 1.5 和 Flash Player 10 中,BitmapData 对象的最大宽度或高度为 8,191 像素,像素总数不能超过 16,777,215 像素。(因此,如果 BitmapData 对象的宽度为 8,191 像素,则其高度只能为 2,048 像素。)在 Flash Player 9 及更早版本和 AIR 1.1 及更早版本中,限制为高度 2,880 像素和宽度 2,880 像素。

但我得到一个似乎没有意义的重要原因是在CS4 文档的下一行:ArgumentError

如果 BitmapData 对象无效(例如,如果它具有height == 0and width == 0)或已通过 处理,则调用 BitmapData 对象的任何方法或属性都会引发 ArgumentError 错误dispose()

所以因为我的图像比 宽8191px,所以它被认为是无效的,导致难以理解ArgumentError

这在调用的上下文中是有道理的draw,但仍然不能解释为什么我能够在src.height不触发错误的情况下调用。

于 2011-03-09T16:15:21.167 回答
0

错误实际上是'参数 0 的类型不正确。应该是类型 IBitmapDrawable' - 而不是 BitmapData。(无论如何,在我的机器上)。

但是 BitmapData 确实是 IBitmapDrawable - 问题在于类型为某个尚未构造的某个类的对象,或者等于 null 实际上并没有实现任何东西。

// Example
var src:BitmapData;
trace(src is IBitmapDrawable); // false

在您的情况下,如果 srcData(Bitmap 对象)没有 bitmapData,它将返回 null 并且 src(BitmapData)设置为 null。因此,当 null 被传递到 draw() 时,它会吓坏,因为 null 不是 IBitmapDrawable。

例如,如果我执行以下操作:

var o:BitmapData = new BitmapData(100, 100, false, 0);
o.fillRect(new Rectangle(0, 0, 100, 100), 0x334455);

var srcData:Bitmap = new Bitmap(o);
var src:BitmapData;

src = srcData.bitmapData;

trace(src is IBitmapDrawable);

var front:BitmapData = new BitmapData(100, 100, false, 0);
front.draw(src as IBitmapDrawable); // works!

但是如果我从 srcData 中删除 o(位图数据),例如:

var srcData:Bitmap = new Bitmap();
var src:BitmapData;

src = srcData.bitmapData;

trace(src is IBitmapDrawable);

var front:BitmapData = new BitmapData(100, 100, false, 0);
front.draw(src as IBitmapDrawable); // Doesn't work!

同样,在您的情况下, Bitmap 对象没有接收任何输入数据。

于 2011-03-09T03:10:51.963 回答