format of ByteArray returned from C is invalid

此生再无相见时 提交于 2020-01-03 06:36:14

问题


following is code snippet:

AS side:(img is reference to an <Image> instance)

        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 code:

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);

In the AS side, when get the dest from C, loader.load(dest) throw an error:Unhandled IOErrorEvent:. text=Error #2124. So How to deal with the byteArray format, so AS side can reorganize and use it as Image source property?


回答1:


if you have a bytearray and you want to load the image source you can do the following:

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

please can you provide a snippet of your AS3 code?




回答2:


I suspect your problem is byte-ordering. You need to flip your bytes after reading from the input ByteArray. For the output ByteArray you either need to flip them again, or set its endian property to Endian.LITTLE_ENDIAN.



来源:https://stackoverflow.com/questions/10210240/format-of-bytearray-returned-from-c-is-invalid

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!