从C返回的ByteArray格式无效

以下是代码段:

AS方:( img引用实例)

  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源属性吗?

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

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

请问您能提供AS3代码片段吗?

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

Interesting Posts