Im trying to send a screenshot to a remote device using TCP. My networking is working fine however I am unable to serialize the OpenGL pixel data into a format that can be de-serialized into a bitmap image on the client. I am using a Bitmap to keep it simple without compression at the moment.
My current attempt is using FreeImage as it is cross platform but would not mind switching Image framework.
glReadPixels( 0, 0, g_iScreenWidth, g_iScreenHeight, GL_RGB, GL_UNSIGNED_BYTE, g_pixels ); FIBITMAP* image = FreeImage_ConvertFromRawBits( g_pixels, g_iScreenWidth, g_iScreenHeight, 3 * g_iScreenWidth, 24, 0xFFFF0000, 0xFF008000, 0xFF0000FF, false ); FIBITMAP *src = FreeImage_ConvertTo32Bits( image ); FreeImage_Unload( image ); // Allocate a raw buffer int width = FreeImage_GetWidth( src ); int height = FreeImage_GetHeight( src ); int scan_width = FreeImage_GetPitch( src ); BYTE *bits = ( BYTE* ) malloc( height * scan_width ); FreeImage_ConvertToRawBits( bits, src, scan_width, 24, 0xFFFF0000, 0xFF008000, 0xFF0000FF, false ); FreeImage_Unload( src ); g_pTCPServer->SendDataToClientsBytes( bits, height * scan_width );
However this does not give me a byte format that can be de-serialized as a bitmap image on a c# application.
Any advice on how I can get the correct format would be appreciated .