summaryrefslogtreecommitdiff
path: root/platform/android/src/image.cpp
blob: 2a33944b18e6762535eb93b21e9c6527b4018595 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#include <mbgl/util/image.hpp>
#include <mbgl/util/string.hpp>

#include <string>

#include "attach_env.hpp"
#include "bitmap_factory.hpp"

namespace mbgl {

PremultipliedImage decodeImage(const std::string& string) {
    auto env{ android::AttachEnv() };

    auto array = jni::Array<jni::jbyte>::New(*env, string.size());
    jni::SetArrayRegion(*env, *array, 0, string.size(),
                        reinterpret_cast<const signed char*>(string.data()));

    auto bitmap = android::BitmapFactory::DecodeByteArray(*env, array, 0, string.size());
    return android::Bitmap::GetImage(*env, bitmap);
}

} // namespace mbgl