我对闪电有点陌生。我知道它几乎过时了,但我正在从事的项目是用Flash编写的。
我目前的任务是从.jpg文件中的任何像素获取RGB数据。到目前为止,我所做的工作如下:
我将图像保存为.fla文件,并将图像本身转换为自己的自定义类"StageWheel",并将BitmapData作为基类。然而,当我这样做时:
var sWheel:StageWheel = new StageWheel();
addChild(sWheel);
sWheel.addEventListener(MouseEvent.CLICK, getColorSample);
var bitmapWheel:BitmapData = new BitmapData(sWheel.width, sWheel.height);我收到一个错误:
“将StageWheel类型的值隐式强制强制为无关类型的flash.display.DisplayObject”
在线上
addChild(sWheel);这个错误意味着什么?我能不能不用addChild这样把东西添加到舞台上呢?
编辑
@LDMS,谢谢你。稍后,我会尝试这样做:
var rgb:uint = bitMapWheel.getPixel(sWheel.mouseX,sWheel.mouseY);得到一个错误
"1061:通过带有静态类型getPixel的引用调用可能未定义的方法flash.display:Bitmap。“
这是什么意思?我可以不在位图上使用getPixel吗?不好意思,由于某种原因,Flash对我来说是非常难学的。
发布于 2015-05-04 17:36:11
您的StageWheel类是BitmapData,它本身不是一个可以添加到舞台上的显示对象。
您需要将位图数据包装到Bitmap中,以使其成为显示对象。
var sWheel:BitmapData = new StageWheel(); //This is bitmap data, which is not a display object, just data at this point.
//to display the bitmap data, you need to create a bitmap and tell that bitmap to use the bitmap data
var bitmapWheel:Bitmap = new Bitmap(sWheel);
//now you can add the bitmap to the display list
addChild(bitmapWheel);编辑问题的第二部分,您需要访问位图的位图数据才能使用getPixel
bitmapWheel.bitmapData.getPixel(bitmapWheel.mouseX,bitmapWheel.mouseY);https://stackoverflow.com/questions/30036202
复制相似问题