从C返回的ByteArray格式无效

时间:2012-04-18 13:19:14

标签: c actionscript-3 flex alchemy

以下是代码段:

AS方:( img引用<Image>实例)

        bitmapData = Bitmap(img.content).bitmapData;
        var pixels:ByteArray = bitmapData.getPixels(bitmapData.rect);
        pixels.position = 0;
        var output:ByteArray = new ByteArray();
        img_width = bitmapData.width;
        img_height = bitmapData.height;
        ////invoke C code by alchemy
        lomoEncoder.encode(pixels, output, img_width, img_height);
        var newImage:Image = new Image();
        //can't show the image
        newImage.source = output;

C代码:

AS3_Val dest;
AS3_Val source;
unsigned char* pixels = (unsigned char *)malloc(Size);
AS3_ByteArray_readBytes(pixels, source, Size);
pixels = darkCornerLomoEffect((unsigned char*)pixels, image_width, image_height);
AS3_ByteArray_writeBytes(dest, (char*) pixels, length);

在AS方面,当从C获取dest时,loader.load(dest)会抛出错误:Unhandled IOErrorEvent:。 text =错误#2124。 那么如何处理byteArray格式,以便AS端可以重新组织并将其用作Image源属性?

2 个答案:

答案 0 :(得分:1)

如果你有一个bytearray并且你想加载图像源,你可以执行以下操作:

var b:ByteArray = new ByteArray();
var f:BitmapData = new BitmapData(100, 100);
f.setPixels(new Rectangle(0, 0, 100, 100), b);

请提供您的AS3代码片段吗?

答案 1 :(得分:1)

我怀疑你的问题是byte-ordering。从输入ByteArray读取后,您需要翻转字节。对于输出ByteArray,您需要再次翻转它们,或将其endian属性设置为Endian.LITTLE_ENDIAN