ActionScript 3 BitmapData 的方法未实现.我如何访问它的方法? [英] ActionScript 3 BitmapData's methods not implemented. How do I access its methods?

查看:13
本文介绍了ActionScript 3 BitmapData 的方法未实现.我如何访问它的方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

最终,我想要做的是对我在运行时加载的一些位图应用伽马校正.我能够创建一个 BitmapData 对象,然后从 BitmapData 创建一个 Bitmap,并且我能够添加 Bitmap 使用 addChild 进入舞台.到现在为止还挺好.但是,如果我尝试以任何方式更改 BitmapData(在创建 Bitmap 之前或之后),我会收到如下警告:

Ultimately, what I'm trying to do is apply gamma correction to some bitmaps that I load at runtime. I was able to create a BitmapData object, then create a Bitmap from the BitmapData, and I was able to add the Bitmap to the stage with addChild. So far so good. But if I try altering the BitmapData in any way (either before or after creating the Bitmap) I get warnings like these:

Warning: The method BitmapData::fillRect() is not implemented
Warning: The method BitmapData::paletteMap() is not implemented
Warning: The method BitmapData::clone() is not implemented

为了尽可能地简化事情,让我们尝试运行 https://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/display/BitmapData.html#paletteMap()

To simplify things as much as possible, let's just try to run the example code at https://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/display/BitmapData.html#paletteMap()

我创建了一个空白的 ActionScript 3 文档,按 F9 并将此代码复制并粘贴到时间轴中,位于 Layer_1:第 1 帧:

I create a blank ActionScript 3 document, press F9 and I copy and paste this code into the timeline, on Layer_1: Frame 1:

import flash.display.Bitmap;
import flash.display.BitmapData;
import flash.geom.Rectangle;
import flash.geom.Point;

var myBitmapData:BitmapData = new BitmapData(80, 80, false, 0x00FF0000);
myBitmapData.fillRect(new Rectangle(20, 20, 40, 40), 0x0000FF00);

var redArray:Array = new Array(256);
var greenArray:Array = new Array(256);

for(var i:uint = 0; i < 255; i++) {
    redArray[i] = 0x00000000;
    greenArray[i] = 0x00000000;
}

redArray[0xFF] = 0x0000FF00;
greenArray[0xFF] = 0x00FF0000;

var bottomHalf:Rectangle = new Rectangle(0, 0, 100, 40);
var pt:Point = new Point(0, 0);
myBitmapData.paletteMap(myBitmapData, bottomHalf, pt, redArray, greenArray);

var bm1:Bitmap = new Bitmap(myBitmapData);
addChild(bm1);

这只是直接从示例中复制的.当我尝试运行它时,日志告诉我 fillRectpaletteMap 没有实现.我已经在 Animate 19 和 Flash Pro CS6 中尝试过,在两个地方都得到了相同的结果.

That's all just copied directly from the example. And when I try running that, the log tells me that fillRect and paletteMap are not implemented. I've tried in Animate 19 and Flash Pro CS6 with the same results in both places.

知道我做错了什么吗?为什么 BitmapData 的方法没有实现,我该如何实现?

Any idea what I'm doing wrong? Why are BitmapData's methods not implemented and how do I implement them?

推荐答案

问题出在 Scaleform Launcher 上,我用它来测试电影.不要使用 Scaleform Launcher 进行测试,而是转到 Control >测试.那里似乎一切正常.

The problem is with the Scaleform Launcher, which I was using to test the movie. Instead of testing with the Scaleform Launcher, go to Control > Test. Everything seems to be working fine there.

遗憾的是,如果您依赖 Scaleform 集成从游戏引擎内部与 Flash 交互,您将无法从 Flash 内部修改位图.Scaleform 似乎省略了 bitmapData 方法背后的所有代码.

Unfortunately, if you depend on the Scaleform integration for interacting with Flash from inside a game engine, you won't be able to modify bitmaps from inside Flash. Scaleform seems to have left out all the code behind bitmapData's methods.

而且我认为任何人都不太可能再次需要对 Flash 中的位图运行伽马校正,但为了以防万一,您可以这样做:

And I think it's not likely that anyone will ever again need to run gamma correction on bitmaps in Flash, but just in case, here's how you do it:

import flash.display.BitmapData;
import flash.geom.Rectangle;
import flash.geom.Point;

var bitmapData:BitmapData = new BeforeColorCorrection();

var rectangle:Rectangle = new Rectangle(0, 0, bitmapData.width, bitmapData.height);
var point:Point = new Point(0, 0);
var redGamma:Array = new Array(256);
var greenGamma:Array = new Array(256);
var blueGamma:Array = new Array(256);
var gamma:Number = 2.0;

var corrected:Number;
var i:int

for(i = 0; i <= 255; i++)
{
    corrected = 255 * Math.pow((i / 255.0), (1.0 / gamma));

    redGamma[i] = uint(corrected) << 16;
    greenGamma[i] = uint(corrected) << 8;
    blueGamma[i] = uint(corrected);
}

bitmapData.paletteMap(bitmapData, rectangle, point, redGamma, greenGamma, blueGamma);

var bitmap:Bitmap = new Bitmap(bitmapData);

addChild(bitmap);

BeforeColorCorrection 是我库中带有Export for ActionScript"的图像.检查.如果 Scaleform 有效,我会在游戏过程中替换该图像并运行一个函数以通过伽马校正使其变亮.

BeforeColorCorrection is an image in my library with "Export for ActionScript" checked. If Scaleform worked, I would replace that image during gameplay and run a function to brighten it via gamma correction.

这篇关于ActionScript 3 BitmapData 的方法未实现.我如何访问它的方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆