ArgumentError:错误#2015:无效的位图数据
我在加载位图数据时遇到问题。我收到以下错误
Engine Init //trace
loadimage//trace
ArgumentError: Error #2015: Invalid BitmapData.
at flash.display::BitmapData()
以下是我的代码。看起来它发生在跟踪 loadimage 之后
package com.objects {
import flash.display.Sprite;
import flash.display.BitmapData;
import flash.display.Bitmap;
import flash.geom.Point;
import flash.geom.Rectangle;
import flash.display.Loader;
import flash.net.URLRequest;
import flash.net.*;
import flash.events.*;
import flash.display.LoaderInfo;
public class gameObject extends Sprite {
protected var w:Number;
protected var h:Number;
protected var image:BitmapData;
protected var canvas:Bitmap;
protected var px:Number;
protected var py:Number;
public function gameObject():void
{
init();
}
private function init():void
{
}
public function loadImage(imageDir:String, w:Number, h:Number, px:Number, py:Number):void
{
this.w = w;
this.y = y;
this.px = px;
this.py = py;
trace("loadimage");
var loader:Loader = new Loader();
loader.contentLoaderInfo.addEventListener(Event.COMPLETE,imageComplete);
loader.load(new URLRequest(imageDir));
}
private function imageComplete(e:Event):void {
var loader:LoaderInfo = LoaderInfo(e.target);
image = Bitmap(loader.content).bitmapData;
drawImage();
}
private function drawImage():void
{
var tilePoint:Point = new Point(0,0);
var tileRect = new Rectangle(py,px,w,h);
trace(loader.content);
var canvasData:BitmapData = new BitmapData(w,h);
trace("got canvas data");
canvasData.copyPixels(image,tileRect,tilePoint);
trace("copied pixels");
canvas = new Bitmap(canvasData);
}
}
}
,我调用的方法就像这样
balls = new Array();
balls[0] = new gameObject();
balls[0].loadImage("com/images/ball.gif", 15,15,0,0);
当我跟踪 Loader.content 时,下面显示的是
Engine Init
loadimage
[object Bitmap]
ArgumentError: Error #2015: Invalid BitmapData.
at flash.display::BitmapData()
I am having problems loading a bitmapData. I am getting the following error
Engine Init //trace
loadimage//trace
ArgumentError: Error #2015: Invalid BitmapData.
at flash.display::BitmapData()
Below is my code. it appears it happens after the trace loadimage
package com.objects {
import flash.display.Sprite;
import flash.display.BitmapData;
import flash.display.Bitmap;
import flash.geom.Point;
import flash.geom.Rectangle;
import flash.display.Loader;
import flash.net.URLRequest;
import flash.net.*;
import flash.events.*;
import flash.display.LoaderInfo;
public class gameObject extends Sprite {
protected var w:Number;
protected var h:Number;
protected var image:BitmapData;
protected var canvas:Bitmap;
protected var px:Number;
protected var py:Number;
public function gameObject():void
{
init();
}
private function init():void
{
}
public function loadImage(imageDir:String, w:Number, h:Number, px:Number, py:Number):void
{
this.w = w;
this.y = y;
this.px = px;
this.py = py;
trace("loadimage");
var loader:Loader = new Loader();
loader.contentLoaderInfo.addEventListener(Event.COMPLETE,imageComplete);
loader.load(new URLRequest(imageDir));
}
private function imageComplete(e:Event):void {
var loader:LoaderInfo = LoaderInfo(e.target);
image = Bitmap(loader.content).bitmapData;
drawImage();
}
private function drawImage():void
{
var tilePoint:Point = new Point(0,0);
var tileRect = new Rectangle(py,px,w,h);
trace(loader.content);
var canvasData:BitmapData = new BitmapData(w,h);
trace("got canvas data");
canvasData.copyPixels(image,tileRect,tilePoint);
trace("copied pixels");
canvas = new Bitmap(canvasData);
}
}
}
And my call the the method is like so
balls = new Array();
balls[0] = new gameObject();
balls[0].loadImage("com/images/ball.gif", 15,15,0,0);
When I trace the Loader.content, below is what shows
Engine Init
loadimage
[object Bitmap]
ArgumentError: Error #2015: Invalid BitmapData.
at flash.display::BitmapData()
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(7)
Flash Player 9 仅支持 2880 px 宽度和高度。
Flash Player 9 only support 2880 px width and height.
还要检查您的图像是否太大。我在大于 3000 像素的图像上遇到此错误...
also check if your image isn't too large. I got this error on images which were bigger then 3000 pixels ...
我认为你想引用 e.target 的 Loader,而不是 LoaderInfo。尝试在 image= 行之前跟踪(loader.content),看看它是否告诉您数据内容是什么类型。
I think you want to reference the Loader of the e.target, not the LoaderInfo. Try to trace(loader.content) right before your image= line and see if it tells you what type of data content is.
尝试将 imageComplete() 更改为:
这应该允许您在错误发生之前捕获错误。下一个问题是为什么你的位图没有被正确解析。
Try changing your imageComplete() into this:
That should allow you to catch the error before it happens. The next question is WHY your bitmap isn't parsed okay.
好的,现在我修好了。如果您仔细查看代码,您将看到为我的类变量“w”设置的属性 Y
Ok , now I fixed it. If you take a good look at the code, you will see the property Y being set for my class varible 'w'
我只是想插话并说我收到此错误的 PNG 文件已被异步写入/损坏的上传截断。
当我后来使用
Loader
/URLRequest
加载 PNG 时,加载成功完成,loader.content
属性返回一个位图,它有一个有效的宽度和高度属性,一切看起来都有效。但是,一旦您尝试访问像素数据(
getPixel32
、copyPixels
或Texture.uploadFromBitmapData
),它就会抛出:I just wanted to chime in and say that I got this error for a PNG file that had been truncated by an asynchronous write / broken upload.
When I later loaded the PNG with a
Loader
/URLRequest
the load completed successfully, theloader.content
property returned aBitmap
, it had a validwidth
andheight
property, everything looks valid.But as soon as you tried to access the pixel data (
getPixel32
,copyPixels
, orTexture.uploadFromBitmapData
), it threw:我用这段代码解决了:
I solved with this code: