[android] - add conversion of non ARGB_8888 images to c++, expose Bitmap#copy on the c++ side
This commit is contained in:
@@ -759,10 +759,7 @@ final class NativeMapView {
|
||||
}
|
||||
|
||||
// Determine pixel ratio
|
||||
float density = image.getDensity() == Bitmap.DENSITY_NONE ? Bitmap.DENSITY_NONE : image.getDensity();
|
||||
float pixelRatio = density / DisplayMetrics.DENSITY_DEFAULT;
|
||||
|
||||
nativeAddImage(name, image, pixelRatio);
|
||||
nativeAddImage(name, image, image.getDensity() / DisplayMetrics.DENSITY_DEFAULT);
|
||||
}
|
||||
|
||||
public void addImages(@NonNull HashMap<String, Bitmap> bitmapHashMap) {
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -43,6 +43,7 @@ public:
|
||||
|
||||
static PremultipliedImage GetImage(jni::JNIEnv&, jni::Object<Bitmap>);
|
||||
static jni::Object<Bitmap> CreateBitmap(jni::JNIEnv&, const PremultipliedImage&);
|
||||
static jni::Object<Bitmap> Copy(jni::JNIEnv&, jni::Object<Bitmap>);
|
||||
|
||||
private:
|
||||
static jni::Class<Bitmap> _class;
|
||||
|
||||
Reference in New Issue
Block a user