The final solution that worked.
https://github.com/tgraupmann/UnrealEngine/blob/4.6-OUYA/Engine/Source/Runtime/Engine/Private/OuyaSDK/OuyaModEditor.cpp#L64
void AOuyaModEditor::AddScreenshot(UTexture2D* screenshot)
{
#if PLATFORM_ANDROID
if (!screenshot)
{
__android_log_print(ANDROID_LOG_ERROR, LOG_TAG, "Screenshot is null");
return;
}
if (!_ouyaModEditor.GetInstance())
{
__android_log_print(ANDROID_LOG_ERROR, LOG_TAG, "OuyaModEditor reference is null");
return;
}
#if ENABLE_VERBOSE_LOGGING
__android_log_print(ANDROID_LOG_VERBOSE, LOG_TAG, "Grab first mipmap");
#endif
FTexture2DMipMap* mipmap = &screenshot->PlatformData->Mips[0];
if (!mipmap)
{
__android_log_print(ANDROID_LOG_ERROR, LOG_TAG, "Mipmap is null");
return;
}
int32 width = mipmap->SizeX;
int32 height = mipmap->SizeY;
#if ENABLE_VERBOSE_LOGGING
__android_log_print(ANDROID_LOG_VERBOSE, LOG_TAG, "Mipmap width=%d height=%d", width, height);
#endif
FByteBulkData* rawImageData = &mipmap->BulkData;
if (!rawImageData)
{
__android_log_print(ANDROID_LOG_ERROR, LOG_TAG, "RawImageData is null");
return;
}
FColor* formatedImageData = static_cast<FColor*>(rawImageData->Lock( LOCK_READ_ONLY));
if (!formatedImageData)
{
__android_log_print(ANDROID_LOG_ERROR, LOG_TAG, "FormatedImageData is null");
return;
}
Config config = Config::ARGB_8888();
Bitmap bitmap = Bitmap::createBitmap(width, height, config);
config.Dispose();
if (!bitmap.GetInstance())
{
__android_log_print(ANDROID_LOG_ERROR, LOG_TAG, "Bitmap reference is null");
return;
}
#if ENABLE_VERBOSE_LOGGING
__android_log_print(ANDROID_LOG_VERBOSE, LOG_TAG, "Created bitmap");
#endif
int* pixels = new int[width * height];
for (int32 y = 0; y < height; ++y)
{
for (int32 x = 0; x < width; ++x)
{
int index = y * width + x;
FColor pixelColor = formatedImageData[index];
uint8 alpha = pixelColor.A;
uint8 red = pixelColor.R;
uint8 green = pixelColor.G;
uint8 blue = pixelColor.B;
int color = alpha << 24 | red << 16 | green << 8 | blue;
pixels[index] = color;
}
}
#if ENABLE_VERBOSE_LOGGING
__android_log_print(ANDROID_LOG_VERBOSE, LOG_TAG, "Set bitmap pixels");
#endif
bitmap.setPixels(pixels, width*height, 0, width, 0, 0, width, height);
#if ENABLE_VERBOSE_LOGGING
__android_log_print(ANDROID_LOG_VERBOSE, LOG_TAG, "Delete pixels");
#endif
delete pixels;
#if ENABLE_VERBOSE_LOGGING
__android_log_print(ANDROID_LOG_VERBOSE, LOG_TAG, "Add Screenshot");
#endif
_ouyaModEditor.addScreenshot(bitmap);
#if ENABLE_VERBOSE_LOGGING
__android_log_print(ANDROID_LOG_VERBOSE, LOG_TAG, "Unlock image buffer");
#endif
rawImageData->Unlock();
#if ENABLE_VERBOSE_LOGGING
__android_log_print(ANDROID_LOG_VERBOSE, LOG_TAG, "Add Screenshot done.");
#endif
#endif
}