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

#include <string>

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

namespace mbgl {

PremultipliedImage decodeImage(Blob blob) {
    auto env{ android::AttachEnv() };

    const auto string = blob.uncompressedData();

    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