I am trying to compress an image, convert it to a string, add it to a JSON object (with some other properties) and then send it via TCP.
Here is how I compress the image:
TArray<uint8> CompressedData;
FImageUtils::CompressImageArray(
1024,
1024,
ColorBuffer,
CompressedData
);
server.Process(CompressedData);
My Process function definition looks like this:
void Process(const TArray<uint8> data);
Now, since I need to send JSON (using rapidjson), I need to convert it to a string.
I have tried:
FString frameAsFString = StringFromBinaryArray(data);
string frameAsString(TCHAR_TO_UTF8(*frameAsFString));
Where StringFromBinaryArray is from Rama:
FString TCPMessengerServer::StringFromBinaryArray(const TArray<uint8>& BinaryArray)
{
//Create a string from a byte array!
const std::string cstr(reinterpret_cast<const char*>(BinaryArray.GetData()), BinaryArray.Num());
//FString can take in the c_str() of a std::string
return FString(cstr.c_str());
}
But the frameAsString looks like this: “?PNG\r\n\u001A\n”
I then tried:
string s(*data.GetData(), sizeof(data));
But from that, frameAsString looks like this:
\u0010\u0010\u0010\u0010\u0010\u0010\u0010\u00
10\u0010\u0010\u0010\u0010\u0010\u0010\u0010\u0010\u0010\u0010\u0010\u0010\u0010\u0010\u0010\u
0010\u0010\u0010\u0010\u0010\u0010\u0010\u0010\u0010\u0010\u0010\u0010\u0010\u0010\u0010\u0010
\u0010\u0010\u0010\u0010\u0010\u0010\u0010\u0010\u0010\u0010\u0010\u0010\u0010\u0010\u0010\u00
10\u0010\u0010\u0010\u0010\u0010\u0010\u0010\u0010\u0010\u0010\u0010\u0010\u0010\u0010\u0010\u
0010\u0010\u0010\u0010\u0010\u0010\u0010\u0010\u0010\u0010\u0010\u0010\u0010\u0010\u0010\u0010
\u0010\u0010\u0010\u0010\u0010\u0010\u0010\u0010\u0010\u0010\u0010\u0010\u0010\u0010\u0010\u00
10\u0010\u0010\u0010\u0010\u0010\u0010\u0010\u0010\u0010\u0010\u0010\u0010\u0010\u0010\u0010\u
0010\u0010\u0010\u0010\u0010\u0010\u0010\u0010\u0010\u0010\u0010\u0010\u0010\u0010\u0010\u0010
\u0010\u0010\u0010\u0010
I don’t think that I am getting the actual image data… just the address or something.
How can I get the actual image data from my const TArray data and convert it to a string so that I can send as JSON?