[android] - add conversion of non ARGB_8888 images to c++, expose Bitmap#copy on the c++ side

This commit is contained in:
Tobrun
2018-02-02 11:16:01 +01:00
committed by Tobrun
parent 0b27909b8b
commit ff747a8c53
3 changed files with 10 additions and 6 deletions

View File

@@ -110,8 +110,7 @@ PremultipliedImage Bitmap::GetImage(jni::JNIEnv& env, jni::Object<Bitmap> bitmap
}
if (info.format != ANDROID_BITMAP_FORMAT_RGBA_8888) {
// TODO: convert
throw std::runtime_error("bitmap decoding: bitmap format invalid");
bitmap = Bitmap::Copy(env, bitmap);
}
const PixelGuard guard(env, bitmap);
@@ -128,5 +127,12 @@ PremultipliedImage Bitmap::GetImage(jni::JNIEnv& env, jni::Object<Bitmap> bitmap
return { Size{ info.width, info.height }, std::move(pixels) };
}
jni::Object<Bitmap> Bitmap::Copy(jni::JNIEnv& env, jni::Object<Bitmap> bitmap) {
using Signature = jni::Object<Bitmap>(jni::Object<Config>, jni::jboolean);
auto static method = _class.GetMethod<Signature>(env, "copy");
auto config = Bitmap::Config::Create(env, Bitmap::Config::Value::ARGB_8888);
return bitmap.Call(env, method, config, (jni::jboolean) false);
}
} // namespace android
} // namespace mbgl