AS3 convert ByteArray of ARGB values to RGB uint
-
22-06-2021 - |
题
I have a C++ QT application that is sending a ByteArray of ARGB values via a TCP socket. The image is 100 x 100. The problem is that when I read off the ByteArray I can't seem to get the image to display right. I've tried lots of different ways and here is AS3 code that's got me the closest.
bitmapData.lock();
for(var x = 0;x<100; x++){
for(var y = 0;y<100; y++){
alphaValue = byteArray.readUnsignedByte();
redValue = byteArray.readUnsignedByte();
greenValue = byteArray.readUnsignedByte();
blueValue = byteArray.readUnsignedByte();
color = redValue << 16 | greenValue << 8 | blueValue;
bitmapData.setPixel(y,x,color);
}
}
bitmapData.unlock();
I'm just not using the alpha value at the moment because I'm not sure what to do with it. Qt says "The image is stored using a 32-bit RGB format (0xffRRGGBB)." I tried using readUnsignedInt()
too, but that didn't work either.
Here is what I'm trying to send and what I see on screen.
Sent : Received in Flash
It's close, but not just right. Does anyone have any idea what I may be doing wrong?
解决方案
Much easier would be to use readUnsignedInt
instead of multiple calls to readByte
. Then use bitmap.setPixel32
instead of setPixel
. That way you don't have to deconstruct and reconstruct the values.
You might also have to switch the endian-ness (e.g. byteArray.endian = Endian.LITTLE_ENDIAN
) depending on how it's encoded. I just can't remember off-hand which way around it is, so you can try that if it doesn't work first time.